Re: [Tutor] Connecting Py 2.7 with visa

2015-05-19 Thread Wilson, Pete
Pip-for-windows worked great! Bob's your uncle! Case closed.

Pete

> -Original Message-
> From: Tutor [mailto:tutor-bounces+pete.wilson=atmel@python.org] On
> Behalf Of Mark Lawrence
> Sent: Friday, May 15, 2015 7:15 PM
> To: tutor@python.org
> Subject: Re: [Tutor] Connecting Py 2.7 with visa
> 
> On 15/05/2015 23:12, Wilson, Pete wrote:
> > Greetings I am trying to write a test executive program using python
> 2.7 on a windows 7 computer. I want to connect to  a Keithley 2100
> voltmeter using National Instruments VISA. I am having trouble
> installing pyvisa. All the documentation refers to using 'pip' and a
> command line "$ pip install pyvisa" . What interface or console is
> this? "$" prompt looks like a Linux command line. How do we do this
> with windows?
> >
> 
> It's a Windows command line prompt.  You can get this by hitting the
> Windows logo key with 'R' and then entering cmd.  However the
> simplest way for you I think is to download this
> https://sites.google.com/site/pydatalog/python/pip-for-windows
> 
> > Do I have to do this? Or can I use the native visa module in Python
> 2.7? Using the help() and dir() features I can get some basic
> information about visa, but the functions have changed, like
> visa.ResourceManager.open_resource is not working. I really liked this
> function... Are there any examples of how to use this new visa? I have
> some working code below that uses pyvisa, can it be converted?
> >
> 
> Please help us to help you.  Stating "is not working" is less than
> useless, please show us exactly what happens.  Cut and paste any
> output, don't rely on typing it as this often results in further errors
> that just confuse the issue.
> 
> > def update_current():
> >  import visa
> >
> >  rm = visa.ResourceManager()
> >  rm.list_resources()
> >
> >  current_1_ma = ""
> >  exe_check = "PASS"
> >
> >  try:
> >  dut_data = open("dut_data.txt", "w")
> >  except:
> >  exe_check = "FAIL"
> 
> Don't use bare excepts as it's asking for trouble.  Much better to
> leave out the error handling to start with and just let your
> programming errors bubble up as stack traces.  Then add in appropriate
> things to catch.  In the above FileNotFoundError amongst others seems
> suitable.
> 
> --
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Myplotlab issue

2015-05-19 Thread bgen...@masonlive.gmu.edu
Hello,

I am currently working with a simple program in Python (just starting out) and 
am getting an error message:

Traceback (most recent call last):
  File "/Users/nomargfan661/Desktop/PythonProjects/chapter3/graphics.py", line 3
from pylab import plot,show
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pylab.py",
 line 1
from matplotlib.pylab import *
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/pylab.py",
 line 269
from matplotlib.pyplot import *
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/pyplot.py",
 line 29
from matplotlib.figure import Figure, figaspect
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.py",
 line 36
from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes/__init__.py",
 line 4
from ._subplots import *
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes/_subplots.py",
 line 10
from matplotlib.axes._axes import Axes
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes/_axes.py",
 line 17
from matplotlib.cbook import _string_to_bool, mplDeprecation
ImportError: cannot import name _string_to_bool

With this program, I am just trying to plot data points as written in a 
textbook from which I am learning.  I have installed everything properly 
(Python, VPython, numpy, and matplotlib (and as a result, pyplot).  The program 
is:

from __future__ import division,print_function

from pylab import plot,show
y = [1.0,2.4,1.7,0.3,0.6,1.8]

plot(y)
show()

I am running Python 2.7 and all modules are compatible with version 2.7 on Mac 
OS X 10.10.  I have tested other programs I have written which use VPython and 
numpy and I have no problems with those.  I only have one program using 
matplotlib, though, so I don’t know what’s wrong.  Would anybody happen to know 
how to help with fixing this issue?

Thanks,
Brandon


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] create a copying tool

2015-05-19 Thread Remco
Hello,

I am new here, and new with Python.
I use Python 2.7 on a windows computer in Pyscripter.

I've got the next problem witch I need some help with:

I need to copy several files, from several folders to a new location in the 
same folder structure as they are now.
And all the files I need to copy are in a text (.txt) file.

The source folder looks like this: (with in some cases even sub-folders or 
sub-sub-folders)
D:\source\folder1
D:\source\folder2
D:\source\folder3
D:\source\folder4
D:\source\folder5

And the list.txt looks like this: (over 250 entries in the original list file) 
D:\source\folder1\1.jpg D:\source\folder1\2.jpg D:\source\folder1\text3.txt 
D:\source\folder1\FLD\pic.tif
In every source folder there different kind of extensions that I need to copy.
I have written the script below, with the help of google, and the only action I 
see is the missings.txt that is produced.
With in it all the files that are not copied.
import os
import shutil

target_dir = r'D:\target\'
source_dir = r'D:\source\'
source_file = r'D:\source\list.txt'
missing_files = open("missings.txt","w")

for line in open('list.txt'):
source_file = os.path.normpath(source_dir +line)
target_file = os.path.normpath(target_dir +line)
if os.path.exists(target_file):
shutil.copyfile(source_file,target_file)
else:
missing_files.write(line)
missing_files.close()
Can someone help my fixing my problem.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Myplotlab issue

2015-05-19 Thread Mark Lawrence

On 19/05/2015 16:58, bgen...@masonlive.gmu.edu wrote:

Hello,

I am currently working with a simple program in Python (just starting out) and 
am getting an error message:

Traceback (most recent call last):
   File "/Users/nomargfan661/Desktop/PythonProjects/chapter3/graphics.py", line 
3
 from pylab import plot,show
   File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pylab.py",
 line 1
 from matplotlib.pylab import *
   File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/pylab.py",
 line 269
 from matplotlib.pyplot import *
   File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/pyplot.py",
 line 29
 from matplotlib.figure import Figure, figaspect
   File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.py",
 line 36
 from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
   File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes/__init__.py",
 line 4
 from ._subplots import *
   File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes/_subplots.py",
 line 10
 from matplotlib.axes._axes import Axes
   File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes/_axes.py",
 line 17
 from matplotlib.cbook import _string_to_bool, mplDeprecation
ImportError: cannot import name _string_to_bool

With this program, I am just trying to plot data points as written in a 
textbook from which I am learning.  I have installed everything properly 
(Python, VPython, numpy, and matplotlib (and as a result, pyplot).  The program 
is:

from __future__ import division,print_function

from pylab import plot,show
y = [1.0,2.4,1.7,0.3,0.6,1.8]

plot(y)
show()

I am running Python 2.7 and all modules are compatible with version 2.7 on Mac 
OS X 10.10.  I have tested other programs I have written which use VPython and 
numpy and I have no problems with those.  I only have one program using 
matplotlib, though, so I don’t know what’s wrong.  Would anybody happen to know 
how to help with fixing this issue?

Thanks,
Brandon



From 
http://stackoverflow.com/questions/26289473/pycharm-error-while-importing-matplotlib-pyplot-as-plt 
"There is a package called six which matplotlib depends on. Check to 
make sure it's installed...".


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] create a copying tool

2015-05-19 Thread Alan Gauld

On 19/05/15 13:20, Remco wrote:


The source folder looks like this: (with in some cases even sub-folders or 
sub-sub-folders)
D:\source\folder1
D:\source\folder2
D:\source\folder3
D:\source\folder4
D:\source\folder5

And the list.txt looks like this: (over 250 entries in the original list file) 
D:\source\folder1\1.jpg D:\source\folder1\2.jpg D:\source\folder1\text3.txt 
D:\source\folder1\FLD\pic.tif
In every source folder there different kind of extensions that I need to copy.


I'm assu ming the files are on separate lines and
the formatting is an email 'feature'? Please make
sure to post in plain text not HTML.



I have written the script below, with the help of google, and the only action I 
see is the missings.txt that is produced.
With in it all the files that are not copied.



import os
import shutil

target_dir = r'D:\target\'
source_dir = r'D:\source\'
source_file = r'D:\source\list.txt'
missing_files = open("missings.txt","w")

for line in open('list.txt'):


Notice that this looks for a list.txt in the same folder
that the script is run from.
You probably wanted to use your source_file variable above:

for line in open(source_file):


source_file = os.path.normpath(source_dir +line)
target_file = os.path.normpath(target_dir +line)
if os.path.exists(target_file):
shutil.copyfile(source_file,target_file)
else:
missing_files.write(line)
missing_files.close()


Again I assume your indentation got mangled by the
email system Please use plain text for code mails,
its impossible to reliably read your mail otherwise.

I suspect the main issue is that list.txt does not
exist in your current folder or that if it does it
doesn't have the files you expect to find in it.

What does your missing.txt say?
Which files is it failing on?

BTW It looks as if you are maybe closing missing.txt
after the first write so it only ever holds one
file? I suspect the last line should be outside
the loop. But then it may be just the indentation
that is confusing things.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] create a copying tool

2015-05-19 Thread Jos Kerc
Hi,

see comments below:

On Tue, May 19, 2015 at 2:20 PM, Remco  wrote:
> Hello,



> import os
> import shutil
>
> target_dir = r'D:\target\'
> source_dir = r'D:\source\'
> source_file = r'D:\source\list.txt'

you are not using this...

> missing_files = open("missings.txt","w")
>
> for line in open('list.txt'):
> source_file = os.path.normpath(source_dir +line)
> target_file = os.path.normpath(target_dir +line)
> if os.path.exists(target_file):

don't you want to check if the source file is existing?

> shutil.copyfile(source_file,target_file)
> else:
> missing_files.write(line)
> missing_files.close()
> Can someone help my fixing my problem.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

HTH,
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Getting import to use a variable name

2015-05-19 Thread Jim Mooney Py3.4.3winXP
I use python help() a good deal but get tired of paging through the
__object__ stuff to get to what I use at my level, so I wrote the following
to omit it. The problem is, I want to import it then use it as shorthelp.py
for different modules so I could just type shorthelp(modulename). Only the
import mechanism won't let me rename. I can only use the hardcoded imported
module name, shutil in this case. If I try x = anothermodule, then import
x, it doesn't work. import sys.argv[1] also doesn't work. Is there any way
to get around this? I'm mostly interested in doing this from the repl
rather than running from the console.
Py3.4 win32

import shutil  #this works to print non  __xxx  helpstrings for a module,
but I can't substitute it.
useful_helps = []
helps = dir(shutil)
for helper in helps:
if helper[0] == '_':
continue
useful_helps.append(helper)

for helper in useful_helps:
print(helper.upper() + ':', helper.__doc__, '\n')

-- 
Jim

After not doing dishes for a week and washing spoon after spoon, fork after
fork, knife after knife - I suddenly understand the mathematical concept of
infinity, which is just one more damn thing after another.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting import to use a variable name

2015-05-19 Thread Ben Finney
"Jim Mooney Py3.4.3winXP"  writes:

> I can only use the hardcoded imported module name, shutil in this
> case. If I try x = anothermodule, then import x, it doesn't work.

Can you show an example of Python code that you would like to work?

I am *guessing* you mean you want this to work::

>>> foo = 'barmodule'
>>> import foo

That doesn't work because the ‘import’ statement requires the name
directly in the source, not as a string value.

You will be pleased to know of the standard library ‘importlib’
library::

>>> import importlib

>>> foo = 'barmodule'
>>> importlib.import_module(foo)

See the documentation for ‘importlib’ for more on this useful library
https://docs.python.org/3/library/importlib>.

-- 
 \“The restriction of knowledge to an elite group destroys the |
  `\   spirit of society and leads to its intellectual |
_o__)impoverishment.” —Albert Einstein |
Ben Finney

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting import to use a variable name

2015-05-19 Thread Jim Mooney Py3.4.3winXP
On 19 May 2015 at 17:18, Ben Finney  wrote:

> You will be pleased to know of the standard library ‘importlib’
> library::
>
> >>> import importlib
>

Yes, I already got importlib to accept a string. But I can't figure how to
get dir to accept it:

>>> x = 'shutil'
>>> import importlib
>>> importlib.__import__(x)

>>>

If I can get dir to accept x I can parse the output to get rid of the __xxx
stuff and print it out.


-- 
Jim

After not doing dishes for a week and washing spoon after spoon, fork after
fork, knife after knife - I suddenly understand the mathematical concept of
infinity, which is just one more damn thing after another.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting import to use a variable name

2015-05-19 Thread Jim Mooney Py3.4.3winXP
On 19 May 2015 at 17:25, Jim Mooney Py3.4.3winXP 
wrote:

>
> If I can get dir to accept x I can parse the output to get rid of the
> __xxx stuff and print it out.
>

By that I mean dir will give me a list of strings I can then use __doc__ on
to get all useful help items.


-- 
Jim

After not doing dishes for a week and washing spoon after spoon, fork after
fork, knife after knife - I suddenly understand the mathematical concept of
infinity, which is just one more damn thing after another.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor