Re: [Tutor] when is a generator "smart?"

2013-06-03 Thread eryksun
On Mon, Jun 3, 2013 at 12:44 AM, Jim Mooney  wrote:
> On 2 June 2013 20:33, eryksun  wrote:
>
>>
>> The base sys.path configured in the registry already has lib-tk:
>>
>> C:\>reg query hklm\software\python\pythoncore\2.7\pythonpath
>>
>> HKEY_LOCAL_MACHINE\software\python\pythoncore\2.7\pythonpath
>> (Default)REG_SZ
>> C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk
>
> Using Python 2.7 on Windows 7
>
> pythonpath turned out to not be in pythoncore, so I was baffled at the
> source of the original problem. Then I searched the registry for
> pythonpath and it was in an entry for an IDE I had just installed,
> didn't like, and uninstalled, but it didn't clean up the registry (a
> lot of programs do that). Only its pythonpath was for 3.3, explaining
> the trouble, since installing was the Last thing I did. I forgot that
> the counter to the Law of Unintended Consequences is "What did I do
> last?"

I looked into PC/getpathp.c. The value of PythonPath shown above is
only a fallback for when Python is embedded. Otherwise the interpreter
can determine sys.prefix from the exe path, and substitute it for the
dots in the following hard-coded path:

.\DLLs;.\lib;.\lib\plat-win;.\lib\lib-tk

However, if PythonPath has subkeys, it always adds the default value
of each subkey to sys.path. I created a subkey to test this, but
otherwise I haven't used this feature.

As to the problem you describe, I'm mystified. Registry settings
(except environment variables) won't bleed over between Python
installations or across application settings in the registry. That was
probably just a private PYTHONPATH setting of the IDE, used for
starting the interpreter as a subprocess.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] when is a generator "smart?"

2013-06-03 Thread Jim Mooney
On 2 June 2013 23:56, eryksun  wrote:
> On Mon, Jun 3, 2013 at 12:44 AM, Jim Mooney  wrote:
>> On 2 June 2013 20:33, eryksun  wrote:


>
> I looked into PC/getpathp.c. The value of PythonPath shown above is
> only a fallback for when Python is embedded. Otherwise the interpreter
> can determine sys.prefix from the exe path, and substitute it for the
> dots in the following hard-coded path:
>
> .\DLLs;.\lib;.\lib\plat-win;.\lib\lib-tk

Using Python 2.7 on Windows 7

Ah, useful. A lot more than is on windows path and PYTHONPATH
obviously gets snuck in there. Sure enough, I queried sys.path and
there's a Lot more in there. But even that wasn't everything since I
saw RLPy and vtk had also set up their own system variables when I
checked the environment. But those are special variables. From now on
if I'm not sure something is on the path I can just query sys.path and
see if it's there. Good to know.

If I dump a package (not sure how to do that beyond just deleting it,
but I've tried some bad ones, so I'd like to) how do I remove it from
sys.path, or do I need to? I know the windows path and the registry
have a bad habit of accumulating stuff that is no longer there, and
just keeping it. Programs add to the windows path, but when you
uninstall them, don't delete from the path, and it grows and grows.
-- 
Jim
Ornhgvshy vf orggre guna htyl
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problem importing modules.

2013-06-03 Thread Alan Gauld

On 03/06/13 07:09, Shreyas Prakash wrote:

I am using Python 2.7

I tried importing a module named hello.py

I got this error message

Traceback (most recent call last): File "", line 1, in import hello
ImportError: No module named hello

I am not sure why, Can you please give me more insight about the proper
syntax and the PYTHONPATH directory.



Please use plain text emails otherwise the formatting gets all messed up 
(as in the error message above)


The most likely problem is that the folder containing hello.py is not in 
your import path. You can fix that by changing your PYTHONPATH 
environment variable or by modifying sys.path.


If you are using Windows then the PYTHONPATH solution is documented in 
my tutor in the Getting Started topic. It describes how to set PATH but 
the process for PYTHONPATH is exactly the same.


Otherwise tell us which OS you are using and we can help.
(Or Google environment variable for your OS, there are lots of web pages 
that describe the process!)


hth
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] when is a generator "smart?"

2013-06-03 Thread Mark Lawrence

On 03/06/2013 08:41, Jim Mooney wrote:

On 2 June 2013 23:56, eryksun  wrote:

On Mon, Jun 3, 2013 at 12:44 AM, Jim Mooney  wrote:

On 2 June 2013 20:33, eryksun  wrote:





I looked into PC/getpathp.c. The value of PythonPath shown above is
only a fallback for when Python is embedded. Otherwise the interpreter
can determine sys.prefix from the exe path, and substitute it for the
dots in the following hard-coded path:

 .\DLLs;.\lib;.\lib\plat-win;.\lib\lib-tk


Using Python 2.7 on Windows 7

Ah, useful. A lot more than is on windows path and PYTHONPATH
obviously gets snuck in there. Sure enough, I queried sys.path and
there's a Lot more in there. But even that wasn't everything since I
saw RLPy and vtk had also set up their own system variables when I
checked the environment. But those are special variables. From now on
if I'm not sure something is on the path I can just query sys.path and
see if it's there. Good to know.

If I dump a package (not sure how to do that beyond just deleting it,
but I've tried some bad ones, so I'd like to) how do I remove it from
sys.path, or do I need to? I know the windows path and the registry
have a bad habit of accumulating stuff that is no longer there, and
just keeping it. Programs add to the windows path, but when you
uninstall them, don't delete from the path, and it grows and grows.



On Windows Vista Control Panel->System->Advanced System Settings->System 
Properties->Advanced->Environment Variables.  The path is displayed as a 
user setting and a system setting, edit either at your own risk. 
Programs are available to clear unused settings from the registry.  I 
use them quite happily but if you're unsure of what you're doing I'd 
just leave things alone, you'll probably sleep better for it :)


--
"Steve is going for the pink ball - and for those of you who are 
watching in black and white, the pink is next to the green." Snooker 
commentator 'Whispering' Ted Lowe.


Mark Lawrence

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


[Tutor] Need Help Modifying a wxPython GUI (scrolling display and logging)

2013-06-03 Thread Matt D
Hello,

I am using an open source wxPython GUI that I like very very much. I
have ideas about some modifications I need but I cannot be bothering the
author too much so I must learn some very specific things about Python
in order to make the modification myself.  First, I need some help
understanding the code behind this GUI.  From reading the comments I
understand that the part of the program written in C++ sends a Python
pickled dictionary to a msg_queue and when Python decodes the pickle the
TextCtrl fields (in the wxPython GUI I am using) receive/display the
appropriate values. And as new messages are received by Python the GUI
fields are cleared to display the new values.

For starters I would like the values to be displayed on the GUI in some
sort of a scrolling panel as they are cleared from the TextCtrl fields
so the user can watch recent activity.  I dont know what the best way to
do this would be; the wxpython.scrolledPanel widget?  I am unclear if
this can be put on the same GUI pane as the TextCtrl fields are and I am
unclear about if I can take the values from the TextCtrl fields or have
to use the pickle or what? I dont see any variables declared (like in
Visual Basic) so its not like I can just make a list and a textbox and
print it.

More importantly I need to save the values from the TextCtrl fields,
preferable in a CSV file, for later inspection.  From looking at the
Logging HOWTO and the Logging Cookbook I see there are alot of loggers
available, or ways to log, but they all look like they are orientated
towards exception handling and debugging so I am unsure what is the best
way to go about this; maybe wxLogTextCtrl ?  Utimately I need to log the
values from the TextCtrl fields in a row of comma separated values
adding a time/date stamp as one of the values.  I need this log so the
data can easily be worked on in excel or SAS.  I need the time/date
stamp for time series analysis.

I attached the code behind the wxPythoin GUI I am using.
Any help will be much appreciated.

Thanks in advance
-- 
Matt D

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  op25_traffic_panel.py
#  
#  Copyright 2013 Balint Seeber 
#  
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#  
#  

import wx
import cPickle as pickle
import gnuradio.gr.gr_threading as _threading

wxDATA_EVENT = wx.NewEventType()

def EVT_DATA_EVENT(win, func):
	win.Connect(-1, -1, wxDATA_EVENT, func)

class DataEvent(wx.PyEvent):
	def __init__(self, data):
		wx.PyEvent.__init__(self)
		self.SetEventType (wxDATA_EVENT)
		self.data = data

	def Clone (self):
		self.__class__ (self.GetId())

class traffic_watcher_thread(_threading.Thread):
	def __init__(self, rcvd_pktq, event_receiver):
		_threading.Thread.__init__(self)
		self.setDaemon(1)
		self.rcvd_pktq = rcvd_pktq
		self.event_receiver = event_receiver
		self.keep_running = True
		self.start()

	def stop(self):
		self.keep_running = False

	def run(self):
		while self.keep_running:
			msg = self.rcvd_pktq.delete_head()
			de = DataEvent (msg)
			wx.PostEvent (self.event_receiver, de)
			del de

# A snapshot of important fields in current traffic
#
class TrafficPane(wx.Panel):

# Initializer
#
def __init__(self, parent, msgq):
wx.Panel.__init__(self, parent)

self.msgq = msgq

sizer = wx.GridBagSizer(hgap=10, vgap=10)
self.fields = {}

label = wx.StaticText(self, -1, "DUID:")
sizer.Add(label, pos=(1,1))
field = wx.TextCtrl(self, -1, "", size=(144, -1), style=wx.TE_READONLY)
sizer.Add(field, pos=(1,2))
self.fields["duid"] = field;

label = wx.StaticText(self, -1, "NAC:")
sizer.Add(label, pos=(2,1))
field = wx.TextCtrl(self, -1, "", size=(144, -1), style=wx.TE_READONLY)
sizer.Add(field, pos=(2,2))
self.fields["nac"] = field;

label = wx.StaticText(self, -1, "Source:")
sizer.Add(label, pos=(3,1))
field = wx.TextCtrl(self, -1, "", size=(144, -1), style=wx.TE_READONLY)
sizer.Add(field, pos=(3,2))
self.fields["source"] = field;

label = wx.StaticText(self, -1, "Destination:")
sizer.Add(label, pos=(4,1))
field = wx.TextCtrl(self, -1, "", size=(144, -1), style=wx.TE_READONLY)
sizer.Add(field, pos=(4,2))
 

Re: [Tutor] when is a generator "smart?"

2013-06-03 Thread Oscar Benjamin
On 3 June 2013 03:50, Jim Mooney  wrote:
> Py 2.7, Py 3.3
> raw_input, input

There are good reasons for this change. Marc already suggested a
solution for writing code that runs under both versions.

> print, print()

If you put "from __future__ import print_function" at the top of your
module you can use the same print function in Python 2.6/2.7 and 3.x.
I recommend doing this rather than bothering with the 2.x print
statement.

> int a / int b = integer division, int a / int b = normal division and
> // is int division

"from __future__ import division" makes 2.6/2.7 behave like 3.x here.
Note that the floor division operator '//' is available in all
versions since 2.2 and always has the same meaning.

Again there are good reasons for this change and I certainly approve of it.

> 'my %s ate my %' % ('dog','shoes'), 'my {0} ate my
> {1}'.format('dog','shoes') --backported

Both % and .format work in all versions since 2.6: there is no
difference in 3.x. There are no plans to remove % formatting so just
use whichever you like.

> range makes a list, range makes an iterator (xrange for an iterator in 2.7)

Similar to Marc's suggestion earlier:

try:
range = xrange
except NameError:
pass

The newer range is IMO better and should be preferred over the older one.

> sort() sorts in place, sorted() returns a list - actually, I think
> that's in both recent Pys.

That is the same in every Python since Python 2.4 (when sorted() was
introduced). The same thing happens for reverse and reversed:

>>> a = [1,2,3]
>>> a
[1, 2, 3]
>>> a.reverse()
>>> a
[3, 2, 1]
>>> reversed([1,2,3])  # reversed returns an iterator

>>> list(reversed([1,2,3])) # so we'll turn it into a list
[3, 2, 1]

> Tkinter is now tkinter - Lord knows why they bothered doing that

I think the expectation when planning the 2.x to 3.x transition was
that most people writing code for both simultaneously would use
automatic code translation. This kind of thing is easily fixed
automatically but that's overkill when writing small scripts. The
recommendation for someone learning Python was expected to be: just
pick a version and only use books/tutorials/documentation for that
version.

There are other differences between 2.x and 3.x that you have not
mentioned. It doesn't really affect my own scientific programming but
the biggest difference is in text handling. Python 3.x uses unicode
for all text by default and uses type safety to protect users from
mixing encoded bytes with unicode text. This is a big change and was,
I think, a big driving factor in the decision to introduce a backward
incompatible version transition for Python. Once that decision was
made it created the opportunity to make lots of other small backward
incompatible changes (e.g. Tkinter -> tkinter).


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


Re: [Tutor] when is a generator "smart?"

2013-06-03 Thread Jim Mooney
On 3 June 2013 07:22, Oscar Benjamin  wrote:

> If you put "from __future__ import print_function" at the top of your
> module you can use the same print function in Python 2.6/2.7 and 3.x.
> I recommend doing this rather than bothering with the 2.x print
> statement.

Using Python 2.7 on Windows 7

That's handy. When I went backward from 3.3 to 2.7, one of the few
things I missed at my level was end= and sep= in print()  .format()
was already backported since I'd learned that. I do like it .format()
better unless you get too fancy with those {}s. I dislike the % format
for some reason. It just looks ugly to me. And as it says in  first
sentence of The Zen of Python from this.py: "Ornhgvshy vf orggre guna
htyl."

As a programming exercise I've been trying to translate Ancient
Pythonaic back to English, but I don't follow Tim Peter's obfuscated
little program yet. Ancient Pythonaic will probably never rival
Klingon ;')

Ah, question just came up. Since I have two pys, when a module is
ported from 2.7 to 3.2 does it always have a different name? If the
names are the same i can see where I can get confused with a pip
install. Unless it is true that if I use pip-3.3 it will always
install a 3.3 module, and if I use pip-2.7 it will always install a
2.7 module. I'd get rid of Py 3.3 for now to avoid confusion, but at
some point, since a lot has not been ported to 3.3 and my second Lutz
book uses 3.3 exclusively, I'll probably need them both anyway. Or
I'll get around to installing virtual environments. But I've already
done too much extraneous fooling around when I should be learning more
Py. Enough with setting up my environment and editors, already. I'm
sick of it.

I'm done with editor tryouts. Wing 101 is just fine but 101 won't do
two Pys without constant changing every time. The pro version will and
it's on my buy list. I judge a restaurant by it's coffee, and so far
of all the editors I tried, Wing is the most intuitive and least
annoying for Py, and it's thoughtful even on small things, like
needing only one dropdown to comment out a block, while others needed
two. That counts if you use commenting-out and print() as the poor
man's debugger. I was hot to have a debugger but once I learned it I
haven't used it since ;')  commenting-out, print(), staring-at, and
getting a cup of coffee seem to work best for now. Maybe later, too.
I'm beginning to feel that if it's longer than a page and looks like
it needs a debugger, it needs breaking up so it doesn't look that way.
My brain can only hold so much before becoming fozzled, and I have a
terrible memory.

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


Re: [Tutor] when is a generator "smart?"

2013-06-03 Thread Chris “Kwpolska” Warrick
On Mon, Jun 3, 2013 at 8:13 PM, Jim Mooney  wrote:
>
> On 3 June 2013 07:22, Oscar Benjamin  wrote:
>
> > If you put "from __future__ import print_function" at the top of your
> > module you can use the same print function in Python 2.6/2.7 and 3.x.
> > I recommend doing this rather than bothering with the 2.x print
> > statement.
>
> Using Python 2.7 on Windows 7
>
> That's handy. When I went backward from 3.3 to 2.7, one of the few
> things I missed at my level was end= and sep= in print()  .format()
> was already backported since I'd learned that. I do like it .format()
> better unless you get too fancy with those {}s. I dislike the % format
> for some reason. It just looks ugly to me. And as it says in  first
> sentence of The Zen of Python from this.py: "Ornhgvshy vf orggre guna
> htyl."
>
> As a programming exercise I've been trying to translate Ancient
> Pythonaic back to English, but I don't follow Tim Peter's obfuscated
> little program yet. Ancient Pythonaic will probably never rival
> Klingon ;')

It is just rot13.  In Python 2, `str.decode('rot13')` would be enough.
 In Python 3, it doesn’t seem to happen so easily.  (If anyone knows
how to do it, please share!)

> Ah, question just came up. Since I have two pys, when a module is
> ported from 2.7 to 3.2 does it always have a different name?

It never does.  And in case it does, the developers are idiots.

> If the names are the same i can see where I can get confused with a pip
> install. Unless it is true that if I use pip-3.3 it will always
> install a 3.3 module, and if I use pip-2.7 it will always install a
> 2.7 module. I'd get rid of Py 3.3 for now to avoid confusion, but at
> some point, since a lot has not been ported to 3.3

http://python3wos.appspot.com/ seems to think otherwise.  60.5% of the
top 200 packages are ported, and two more are getting close
(werkzeug+flask[0]).

[0]: 
http://www.reddit.com/r/Python/comments/1fd69b/werkzeug_and_flask_git_repositories_have_early/

--
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need Help Modifying a wxPython GUI (scrolling display and logging)

2013-06-03 Thread Alan Gauld

On 03/06/13 15:01, Matt D wrote:


I am using an open source wxPython GUI that I like very very much. I
have ideas about some modifications I need but I cannot be bothering the
author too much so I must learn some very specific things about Python


OK, we can help on the python bits but not so much on the wxPython 
library. For that you'd be better off using the wxPython mailing list.



For starters I would like the values to be displayed on the GUI in some
sort of a scrolling panel as they are cleared from the TextCtrl fields


Assuming the GUI uses a standard Text control then I think it should be 
possible to turn that into a scrolled pane and then just stop the delete 
code from deleting. ie make the new text appear below the existing 
stuff. Is that what you want?


I'm fairly sure you can add scroll bars to the wxPython Text widget...


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] when is a generator "smart?"

2013-06-03 Thread Jim Mooney
On 3 June 2013 11:47, Chris “Kwpolska” Warrick  wrote:
>
>> Ah, question just came up. Since I have two pys, when a module is
>> ported from 2.7 to 3.2 does it always have a different name?
>
> It never does.  And in case it does, the developers are idiots.

Using Python 2.7 on Windows 7

So to clarify, the module names are the same on 2.7 and 3.3. Does that
mean the module writers set the module so it will only install on the
proper Py version, failing if it can't find it, so I don't have to
think about that?

Incidentally, for those nutty enough to run two Pys on Win, with Wing
101, I realized you can get Wing 101 to run either, without having to
reconfigure it all the time, by setting up a Guest account in Windows,
and configuring the second Wing for Py 3.3, run as Guest, with the
primary as 2.7. This is helpful since some online sources I read are
for one Py and some are for another.

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


Re: [Tutor] when is a generator "smart?"

2013-06-03 Thread Oscar Benjamin
On 3 June 2013 21:36, Jim Mooney  wrote:
> So to clarify, the module names are the same on 2.7 and 3.3. Does that
> mean the module writers set the module so it will only install on the
> proper Py version, failing if it can't find it, so I don't have to
> think about that?

Maybe or maybe not. When you run 'python setup.py install' (this
happens implicitly when using pip), Python will try to run the
setup.py script. At this point the script can do anything that its
author likes. It could check for versions, it could just install and
be broken, it could delete random files or damage your system in a
malicious way. The author may have written the package at a time when
Python 3 didn't exist so they didn't see the need to check for Python
version and wrote code that wouldn't work in Python 3.

There is progress on improving this situation by formalising the
metadata that is supplied with Python packages so that it can be used
more effectively by tools such as pip. The current (unaccepted) PEP
for this is here (see the environment markers section):
http://www.python.org/dev/peps/pep-0426/

> Incidentally, for those nutty enough to run two Pys on Win, with Wing
> 101, I realized you can get Wing 101 to run either, without having to
> reconfigure it all the time, by setting up a Guest account in Windows,
> and configuring the second Wing for Py 3.3, run as Guest, with the
> primary as 2.7. This is helpful since some online sources I read are
> for one Py and some are for another.

If you have py.exe (which you should if you've installed Python 3.3 on
Windows) then you can run any installed Python version as 'py -2.7
myscript.py' or 'py -3.3 myscript.py' to choose the version of Python
that will run myscript.py. I find it easier and clearer to do that
explicitly on the command line when I want to test different versions.


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


Re: [Tutor] when is a generator "smart?"

2013-06-03 Thread bob gailer

On 6/1/2013 11:58 PM, Jim Mooney wrote:


 squarelist = (c**2 for c in range(x,y) if c%2 != 0)


can be simplified to:

squarelist = (c**2 for c in range(x,y,2))

as long as x is odd.

--
Bob Gailer
919-636-4239
Chapel Hill NC

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


[Tutor] I think I found what I'm looking for.

2013-06-03 Thread Michael Sparks
speech.py is a Python module that provides a clean interface to Windows's
voice recognition and text-to-speech capabilities. But it requires Windows
XP or Vista, and Python 2.4 or 2.5. I use Windows 7.

another one I found; Dragonfly  is a speech recognition framework. It is a
Python package which offers a high-level object model and allows its users
to easily write scripts, macros, and programs which use speech recognition.

I think that I'm satisfied with speech.py but it might not work on Windows
7. I'm very interested in Dragonfly but I don't think that I've ever used a
framework or even know what a framework is.

before you answer my question. I'm going to sourceforge to see if there is
any speech recognition software out there. I'm in a coffee shop right now
and I seem to have no internet access at home, the sober/recovery house,
and I'm not sure if this computer will allow me to download software onto
my pen drive.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] when is a generator "smart?"

2013-06-03 Thread Jim Mooney
On 3 June 2013 14:41, Oscar Benjamin  wrote:

> Maybe or maybe not. When you run 'python setup.py install' (this
> happens implicitly when using pip), Python will try to run the
> setup.py script. At this point the script can do anything that its
> author likes. It could check for versions, it could just install and
> be broken, it could delete random files or damage your system in a
> malicious way. The author may have written the package at a time when
> Python 3 didn't exist so they didn't see the need to check for Python
> version and wrote code that wouldn't work in Python 3.

Using Python 2.7 on Windows 7

That's scary. But are we talking modules from wherever or PyPI
modules? I figured the modules on the official PyPI index would be
checked to some degree, and be safe. I guess I'll always look into the
setup.py to see if it contains any obvious gotchas. Oops - pip
downloads and installs automatically - I never see setup.py. Might be
best to download, inspect, then run the install.

Good trick for running different Py versions from the command line
without accidentally confusing them. You never know what you're going
to learn here ;')  I was qualifying the path to each version but that
gets to be a pain. As for Wing, I just meant running as Guest is a
windows trick for running two different versions of the same program
for two different Pys without reconfiguring the IDE. Wing 101 has only
one config since it's the free version and doesn't do projects. So you
have to reconfig every time to run different Pys from the IDE unless
you do that trick. No doubt there's something similar in Linux.

Jim
>
> There is progress on improving this situation by formalising the
> metadata that is supplied with Python packages so that it can be used
> more effectively by tools such as pip. The current (unaccepted) PEP
> for this is here (see the environment markers section):
> http://www.python.org/dev/peps/pep-0426/
>
>> Incidentally, for those nutty enough to run two Pys on Win, with Wing
>> 101, I realized you can get Wing 101 to run either, without having to
>> reconfigure it all the time, by setting up a Guest account in Windows,
>> and configuring the second Wing for Py 3.3, run as Guest, with the
>> primary as 2.7. This is helpful since some online sources I read are
>> for one Py and some are for another.
>
> If you have py.exe (which you should if you've installed Python 3.3 on
> Windows) then you can run any installed Python version as 'py -2.7
> myscript.py' or 'py -3.3 myscript.py' to choose the version of Python
> that will run myscript.py. I find it easier and clearer to do that
> explicitly on the command line when I want to test different versions.
>
>
> Oscar
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor



-- 
Jim
Ornhgvshy vf orggre guna htyl
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I think I found what I'm looking for.

2013-06-03 Thread David Robinow
On Mon, Jun 3, 2013 at 7:32 PM, Michael Sparks
 wrote:
> speech.py is a Python module that provides a clean interface to Windows's
> voice recognition and text-to-speech capabilities. But it requires Windows
> XP or Vista, and Python 2.4 or 2.5. I use Windows 7.
> ...
> I think that I'm satisfied with speech.py but it might not work on Windows
> 7.
 It works fine with Windows 7.  It works fine with Python 2.7
I haven't tried Dragonfly. (It should be better)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] selenium programs stopped working

2013-06-03 Thread Benjamin Fishbein
I'm using selenium webdriver with python 2.7. I have some programs I wrote with 
it and they've been working properly for some months.
But today I tried to write a new program with the selenium module.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://www.python.org";) # actually I go to other sites, not 
python.org
# now there's more but the program never gets to it

The Firefox web browser opens, but it doesn't go to any page. The url doesn't 
even appear in the box at the top of the webbrowser where urls go.
Do you know what is causing this problem? The only thing I can think of is that 
there's some problem in the settings. I shut down the computer and turned it 
back on, but the problem remains.
Any help would be greatly appreciated.
Thanks,
Ben

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


Re: [Tutor] selenium programs stopped working

2013-06-03 Thread Benjamin Fishbein
btw I'm on a Mac running 10.7.
And after a couple minutes of not loading any webpage, the program gives me 
this error:

Traceback (most recent call last):
  File "/Users/bfishbein/Documents/s_buy2.py", line 7, in 
driver = webdriver.Firefox()
  File 
"/Library/Python/2.7/site-packages/selenium/webdriver/firefox/webdriver.py", 
line 58, in __init__
self.binary, timeout),
  File 
"/Library/Python/2.7/site-packages/selenium/webdriver/firefox/extension_connection.py",
 line 47, in __init__
self.binary.launch_browser(self.profile)
  File 
"/Library/Python/2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py",
 line 48, in launch_browser
self._wait_until_connectable()
  File 
"/Library/Python/2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py",
 line 95, in _wait_until_connectable
self.profile.path, self._get_firefox_output()))
WebDriverException: Message: "Can't load the profile. Profile Dir: 
/var/folders/vm/8th3csp91qb47xbhqhb4gcmhgn/T/tmpPeqacA Firefox output: *** 
LOG addons.xpi: startup\n*** LOG addons.xpi: Skipping unavailable install 
location app-system-share\n*** LOG addons.xpi: checkForChanges\n*** LOG 
addons.xpi: No changes found\n" 

I can't make any sense of this.
Ben



On Jun 3, 2013, at 8:08 PM, Benjamin Fishbein wrote:

> I'm using selenium webdriver with python 2.7. I have some programs I wrote 
> with it and they've been working properly for some months.
> But today I tried to write a new program with the selenium module.
> 
> from selenium import webdriver
> from selenium.webdriver.common.keys import Keys
> 
> driver = webdriver.Firefox()
> driver.get("http://www.python.org";) # actually I go to other sites, not 
> python.org
> # now there's more but the program never gets to it
> 
> The Firefox web browser opens, but it doesn't go to any page. The url doesn't 
> even appear in the box at the top of the webbrowser where urls go.
> Do you know what is causing this problem? The only thing I can think of is 
> that there's some problem in the settings. I shut down the computer and 
> turned it back on, but the problem remains.
> Any help would be greatly appreciated.
> Thanks,
> Ben
> 

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


Re: [Tutor] when is a generator "smart?"

2013-06-03 Thread Oscar Benjamin
On 4 June 2013 01:00, Jim Mooney  wrote:
>> Maybe or maybe not. When you run 'python setup.py install' (this
>> happens implicitly when using pip), Python will try to run the
>> setup.py script. At this point the script can do anything that its
>> author likes. It could check for versions, it could just install and
>> be broken, it could delete random files or damage your system in a
>> malicious way. The author may have written the package at a time when
>> Python 3 didn't exist so they didn't see the need to check for Python
>> version and wrote code that wouldn't work in Python 3.
>
> Using Python 2.7 on Windows 7

I guess at some point that someone told you to "always state the
Python version and OS" but really it's only necessary when it's
relevant. Sometimes it might not be obvious if it's relevant or not
and if so it's best to mention it. Mainly it will be relevant if
you're talking about actual code or the availability of particular
modules (for this post it isn't).

> That's scary. But are we talking modules from wherever or PyPI
> modules?

You always should be cautious about downloading code and running it.
Even more so if you're going to use admin/root privileges to run it.
However I've never actually had a problem with this whether I get
packages from PyPI or from sourceforge/github/bitbucket etc. In the
case of pip, when you run 'pip install X' what you need to understand
is that PyPI can only guarantee that the code there was uploaded by
whoever initially registered the name X on PyPI. Anyone can register
the name but once they have they will control that name in the PyPI
namespace unless PyPI or their PyPI account gets hacked. There are a
number of ongoing efforts to improve security around PyPI and one part
of that is to abolish the "run setup.py to install" concept.

> I figured the modules on the official PyPI index would be
> checked to some degree, and be safe.

No they are not. You can test this yourself: anyone can register a
name and upload any code they want. There are two protections that
PyPI currently offers. The first is that once a name is registered no
one else can upload code under that name. The second is that if
someone does upload malware and it is reported to the PyPI admins then
they can remove it but only retrospectively. There is no proactive
checking of the code that goes onto PyPI.

> I guess I'll always look into the
> setup.py to see if it contains any obvious gotchas. Oops - pip
> downloads and installs automatically - I never see setup.py. Might be
> best to download, inspect, then run the install.

I personally rarely do this and would only actually bother if
installing a very obscure package. I think that widely used packages
can be trusted (in this sense) not to do harm.


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


Re: [Tutor] selenium programs stopped working

2013-06-03 Thread Oscar Benjamin
Please don't top-post on this list (and many others). Inline or
bottom-posted responses are usually preferred like the way that I've
rearranged your message below.

On 4 June 2013 02:27, Benjamin Fishbein  wrote:
> On Jun 3, 2013, at 8:08 PM, Benjamin Fishbein wrote:
>
>> I'm using selenium webdriver with python 2.7. I have some programs I wrote 
>> with it and they've been working properly for some months.
>> But today I tried to write a new program with the selenium module.
>>
>> from selenium import webdriver
>> from selenium.webdriver.common.keys import Keys
>>
>> driver = webdriver.Firefox()
>> driver.get("http://www.python.org";) # actually I go to other sites, not 
>> python.org
>> # now there's more but the program never gets to it
>>
>> The Firefox web browser opens, but it doesn't go to any page. The url 
>> doesn't even appear in the box at the top of the webbrowser where urls go.
>> Do you know what is causing this problem? The only thing I can think of is 
>> that there's some problem in the settings. I shut down the computer and 
>> turned it back on, but the problem remains.
>> Any help would be greatly appreciated.
>
> btw I'm on a Mac running 10.7.
> And after a couple minutes of not loading any webpage, the program gives me 
> this error:
>
> Traceback (most recent call last):
>   File "/Users/bfishbein/Documents/s_buy2.py", line 7, in 
> driver = webdriver.Firefox()
>   File 
> "/Library/Python/2.7/site-packages/selenium/webdriver/firefox/webdriver.py", 
> line 58, in __init__
> self.binary, timeout),
>   File 
> "/Library/Python/2.7/site-packages/selenium/webdriver/firefox/extension_connection.py",
>  line 47, in __init__
> self.binary.launch_browser(self.profile)
>   File 
> "/Library/Python/2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py",
>  line 48, in launch_browser
> self._wait_until_connectable()
>   File 
> "/Library/Python/2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py",
>  line 95, in _wait_until_connectable
> self.profile.path, self._get_firefox_output()))
> WebDriverException: Message: "Can't load the profile. Profile Dir: 
> /var/folders/vm/8th3csp91qb47xbhqhb4gcmhgn/T/tmpPeqacA Firefox output: 
> *** LOG addons.xpi: startup\n*** LOG addons.xpi: Skipping unavailable install 
> location app-system-share\n*** LOG addons.xpi: checkForChanges\n*** LOG 
> addons.xpi: No changes found\n"
>
> I can't make any sense of this.

Unfortunately neither can I as I've never used selenium. Someone may
respond with a good answer to this but I also wouldn't be surprised if
no one here understood your problem. This list is mainly for people
learning the basics of Python and I think that this seems like quite a
specialist problem that might be better directed at a
mailing-list/forum that is primarily for selenium/firefox (I'm not
sure as I don't really understand what you're doing).


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


Re: [Tutor] when is a generator "smart?"

2013-06-03 Thread eryksun
On Mon, Jun 3, 2013 at 3:41 AM, Jim Mooney  wrote:
> Ah, useful. A lot more than is on windows path and PYTHONPATH
> obviously gets snuck in there. Sure enough, I queried sys.path and
> there's a Lot more in there.

The path for the script comes first, followed by the contents of the
PYTHONPATH environment variable, if present. Next it adds the optional
zip library, additional paths from subkeys of PythonPath in HKCU/HKLM,
the core path string (expanded for sys.prefix / PYTHONHOME) that I
already mentioned, and also the path of the executable (e.g.
python.exe).

Next, site.py is imported (if you didn't use the -S option), which
adds lib\site-packages and paths from .pth files if they exist. If
you've installed a package with --user, it will also add
"%AppData%\Python\Python27\site-packages". Finally, it tries to import
sitecustomize.py and usercustomize.py.

> If I dump a package (not sure how to do that beyond just deleting it,
> but I've tried some bad ones, so I'd like to) how do I remove it from
> sys.path, or do I need to?

An exe/msi installer should clean up after itself when you uninstall.
With pip, you can "pip uninstall". With easy_install, use "-mxN
PackageName" (that should remove scripts and clear the package from
setuptools.pth), and then manually delete the directory.

As to any .pth files left behind, the directories listed in them won't
be added to sys.path if they no longer exist. So leaving them around
only costs a few milliseconds of startup time. If for some reason a
package stored paths in a subkey of PythonPath, you'll have to remove
the subkey to keep it from being added to sys.path -- but I haven't
actually seen a package use this option. .pth files are simpler and
cross-platform.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor