Re: How to investigate web script not running?

2012-09-30 Thread Gilles
On Sat, 29 Sep 2012 10:05:25 -0700 (PDT), Ramchandra Apte
 wrote:
>> Definitely not plug 'n play :-/
>
>Well the plug and play standard is superseded by USB practically.

Indeed ;-)

Anyway, Support finally got back to me, and it turns out that they
have Flup alreay installed on shared hosts, so I just have to provide
a WSGI script. OTOH, mod_fcgid is confured to wait 5mn or so before
checking if the script was edited, so I'll have to use a test host for
development and only use the shared host for deployment.

Thank all.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Should one always add super().__init__() to the __init__?

2012-09-30 Thread Steven D'Aprano
On Sun, 30 Sep 2012 00:08:03 -0600, Ian Kelly wrote:

> On Sat, Sep 29, 2012 at 10:40 PM, Steven D'Aprano
>  wrote:
>> On Sat, 29 Sep 2012 17:51:29 -0400, Piet van Oostrum wrote:
>>
>>> It is not necesarily calling the parent class. It calls the
>>> initializer of the next class in the MRO order and what class that is
>>> depends on the actual multiple inheritance structure it is used in,
>>> which can depend on subclasses that you don't know yet. This makes it
>>> even worse.
>>
>> I don't quite follow you here. It sounds like you are saying that if
>> you have these classes:
>>
>> # pre-existing classes
>> class A(object): pass
>> class B(object): pass
>>
>> # your class
>> class C(A, B): pass
>>
>> and somebody subclasses A or B, the MRO of C will change. That is not
>> actually the case as far as I can see.
> 
> The MRO of C will not change, but the class that follows C may be
> different in the MRO of a subclass.

To quote a famous line from the movie Cool Hand Luke, "what we have here, 
is a failure to communicate."

What do you mean by one class following another? Which class is it that 
follows C? What subclass are you talking about, and what is it 
subclassing?

I have absolutely no idea what you are trying to get across here, why you 
think it is important, or whether it matches what Piet is trying to say.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get progress in python script.

2012-09-30 Thread Oscar Benjamin
On 28 September 2012 17:26, Rolando Cañer Roblejo
wrote:

> Hi all,
>
> Please, I need you suggest me a way to get statistics about a progress of
> my python script. My python script could take a lot of time processing a
> file, so I need a way that an external program check the progress of the
> script. My first idea was that the python script write a temp file showing
> the progress and the external program can check that file, but I think
> might happen file read/write locking issues.
>

Why does it need to be an external program?

I often write python scripts that run in the terminal and spend a long time
processing a file or list of files. The simply way to report progress in
that case is to just print something out every now and again. When I'm
feeling extravagant I use the progressbar library from PyPI:
http://pypi.python.org/pypi/progressbar/

With progressbar you can get a very nice display of current progress, ETA,
etc:

'''
import os.path
import sys

from progressbar import ProgressBar, Percentage, Bar, ETA

def start(text, size):
widgets = [text + ' ', Percentage(), ' ', Bar(), ETA()]
return ProgressBar(widgets=widgets, maxval=size).start()

def process_file(path):
pbar = start(os.path.basename(path), os.path.getsize(path))
with open(path) as fin:
for line in fin:
pbar.update(pbar.currval + len(line))
words = line.split()
pbar.finish()

for path in sys.argv[1:]:
process_file(path)
'''

Oscar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Missing library path (WIndows)

2012-09-30 Thread Kwpolska
On Sat, Sep 29, 2012 at 10:32 PM, FPEFPE  wrote:
> On Saturday, September 29, 2012 4:02:13 AM UTC-4, Kwpolska wrote:
>>
>> Python has problems with encoding the arguments to look properly with
>>
>> the crappy Windows cmd.exe encodings. They cannot be encoded for some
>>
>> reason.  You may need magic, but I’m not quite sure what in Py3k
>>
>> (bytestrings?)
>>
>>
>>
>> --
>>
>> Kwpolska 
>>
>> stop html mail  | always bottom-post
>>
>> www.asciiribbon.org | www.netmeister.org/news/learn2quote.html
>>
>> GPG KEY: 5EAAEA16
>
> Hello -- thanks for the reply ... is "magic" a debugging tool?
> --
> http://mail.python.org/mailman/listinfo/python-list

No, no, no!  I meant “do some magic with the string”.  In Py2k, it
would be str.decode(), but I don’t know what to do in Py3k.

-- 
Kwpolska 
stop html mail  | always bottom-post
www.asciiribbon.org | www.netmeister.org/news/learn2quote.html
GPG KEY: 5EAAEA16
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Should one always add super().__init__() to the __init__?

2012-09-30 Thread Manuel Pégourié-Gonnard
Steven D'Aprano scripsit :

> On Sun, 30 Sep 2012 00:08:03 -0600, Ian Kelly wrote:
>
>> On Sat, Sep 29, 2012 at 10:40 PM, Steven D'Aprano
>>  wrote:
>>> On Sat, 29 Sep 2012 17:51:29 -0400, Piet van Oostrum wrote:
>>>
 It is not necesarily calling the parent class. It calls the
 initializer of the next class in the MRO order and what class that is
 depends on the actual multiple inheritance structure it is used in,
 which can depend on subclasses that you don't know yet. This makes it
 even worse.
>>>
>>> I don't quite follow you here. It sounds like you are saying that if
>>> you have these classes:
>>>
>>> # pre-existing classes
>>> class A(object): pass
>>> class B(object): pass
>>>
>>> # your class
>>> class C(A, B): pass
>>>
>>> and somebody subclasses A or B, the MRO of C will change. That is not
>>> actually the case as far as I can see.
>> 
>> The MRO of C will not change, but the class that follows C may be
>> different in the MRO of a subclass.
>
> To quote a famous line from the movie Cool Hand Luke, "what we have here, 
> is a failure to communicate."
>
> What do you mean by one class following another?  Which class is it
> that follows C? What subclass are you talking about, and what is it
> subclassing?
>
I think Piet's (and Ian's) point is, you can't assume that
super().__init__, written in a method of C, is always going to refer to
__init__ of the parent class of C, when a subclass of C is instanciated.

For example:

class C:
def __init__(self):
print("C init, calling C's parent init?")
super().__init__() # sic

class NotParentOfC:
def __init__(self):
print("NotParentOfC init")

class Sub(C, NotParentOfC):
pass

spam = Sub()

When Sub is instantiated, the line marked "sic" calls
NotParentOfC.__init, not object.__init__ (as if would if C was
instantiated).

-- 
Manuel Pégourié-Gonnard - http://people.math.jussieu.fr/~mpg/



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python file API

2012-09-30 Thread Ramchandra Apte
On Tuesday, 25 September 2012 03:05:16 UTC+5:30, zipher  wrote:
> For some time now, I've wanted to suggest a better abstraction for the  
> type in Python.  It currently uses an antiquated C-style interface for moving 
> around in a file, with methods like tell() and seek().  But after attributes 
> were introduced to Python, it seems it should be re-addressed.
> 
> 
> 
> Let file-type have an attribute .pos for position.   Now you can get rid of 
> the seek() and tell() methods and manipulate the file pointer more easily 
> with standard arithmetic operations. 
> 
> 
> 
> >>> file.pos = x0ae1  #move file pointer to an absolute address 
> 
> >>> file.pos +=1#increment the file pointer one byte
> 
> >>> curr_pos = file.pos  #read current file pointer
> 
> 
> 
> You've now simplified the API by the removal of two obscure legacy methods 
> and replaced them with a more basic one called "position".
> 
> 
> 
> Thoughts?
> 
> 
> 
> markj

+1
-- 
http://mail.python.org/mailman/listinfo/python-list


Can somebody give me an advice about what to learn?

2012-09-30 Thread tcgo
Hi!
I'm really new to Usenet/Newsgroups, but... I'd like to learn some new 
programming language, because I learnt a bit of Perl though its OOP is ugly. 
So, after searching a bit, I found Python and Ruby, and both of they are cute.
So, assuming you'll say me "learn python", why should I learn it over Ruby?
Thanks!
PS: I don't want to start a flame-war, I just want an advice if it's possible 
please!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [RELEASED] Python 3.3.0

2012-09-30 Thread Georg Brandl

On 09/29/2012 06:53 PM, Antoine Pitrou wrote:


Hello,

I've created a 3.3 category on the buildbots:
http://buildbot.python.org/3.3/
http://buildbot.python.org/3.3.stable/

Someone will have to update the following HTML page:
http://python.org/dev/buildbot/


Should be done now.

Georg


--
http://mail.python.org/mailman/listinfo/python-list


Re: Can somebody give me an advice about what to learn?

2012-09-30 Thread Chris Angelico
On Sun, Sep 30, 2012 at 10:58 PM, tcgo  wrote:
> Hi!
> I'm really new to Usenet/Newsgroups, but... I'd like to learn some new 
> programming language, because I learnt a bit of Perl though its OOP is ugly. 
> So, after searching a bit, I found Python and Ruby, and both of they are cute.
> So, assuming you'll say me "learn python", why should I learn it over Ruby?
> Thanks!
> PS: I don't want to start a flame-war, I just want an advice if it's possible 
> please!

I'm not going to touch Ruby, partly because I don't know it, and
partly to avoid a flame war, but here's some good reasons to learn
Python:

* It's a modern, object-oriented, high level language.
* As of version 3.3 (do make sure you grab this one, there's lots of
enhancements), it has absolutely correct AND efficient Unicode string
handling. I know of only one other language that can store "Hello" as
a five-byte string, while simultaneously allowing perfect handling of
the entire Unicode range.
* Python's syntax is clean and easy to handle. Be aware, though, that
some things are distinctly different from C-family languages.
* You get an excellent set of modules. Python has "batteries included"
(the standard library is extensive) and a whole set of custom
batteries on speed dial (check out PyPI).
* Easy networking support. You can write servers or clients for many
popular internet protocols with just a few lines of code. Simple TCP
sockets are also easy.
* Python is an open source project with a permissive license.
* Superb community support. You can ask a question here and get a
response in minutes. :) You're not going to be left hanging when you
have a problem.
* With very VERY few exceptions, your code will run flawlessly on any
of the many platforms Python supports.

Python does have some issues, though; you'll either appreciate the
syntax or absolutely hate it, and there's no efficient and reliable
way to change/reload code in a running application (not often an
issue).

I'm sure others will add to this list, and there's at least one entry
that someone's likely to disagree with me on, but there's a start!

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can somebody give me an advice about what to learn?

2012-09-30 Thread Tim Chase
On 09/30/12 07:58, tcgo wrote:
> So, assuming you'll say me "learn python", why should I learn it
> over Ruby?

For me, most of Chris's answers apply to both Python and Ruby.
Well, I can't speak regarding the Ruby community being as awesome,
but it doesn't seem to scare off folks.

*READABILITY* is my main reason for choosing Python, particularly
over Ruby.  I can come back to Python code I wrote 5+ years ago, and
it takes me mere minutes to reorient myself to the code.  I can't do
that with most other languages, where it often takes me hours or
days to unwind the code.

-tkc



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can somebody give me an advice about what to learn?

2012-09-30 Thread Rodrick Brown
On Sun, Sep 30, 2012 at 8:58 AM, tcgo  wrote:

> Hi!
> I'm really new to Usenet/Newsgroups, but... I'd like to learn some new
> programming language, because I learnt a bit of Perl though its OOP is
> ugly. So, after searching a bit, I found Python and Ruby, and both of they
> are cute.
> So, assuming you'll say me "learn python", why should I learn it over Ruby?
> Thanks!
>

Python comes stock on most Linux distro's and many RPM based distros uses
Python itself as a core scripting language unlike Ruby, that's why I choose
Python over Ruby 3-4 years back when I was debating which one I should
learn.

PS: I don't want to start a flame-war, I just want an advice if it's
> possible please!
>

This is a Python mailinglist so I doubt you can ignite any flamewar's
between Python vs Ruby! :)


> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can somebody give me an advice about what to learn?

2012-09-30 Thread Roy Smith
In article ,
 Chris Angelico  wrote:

> there's no efficient and reliable way to change/reload code in a 
> running application (not often an issue).

What we do (largely cribbed from django's runserver) is start up a 
thread which once a second, looks at all the modules in sys.modules, 
checks to see if the modification time for their source files has 
changed, and if so, restarts the application.  This is hugely convenient 
when developing any kind of long-running application.  You don't need to 
keep restarting the application; just edit the source and changes take 
effect (almost) immediately.

Not sure if this is what you had in mind.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can somebody give me an advice about what to learn?

2012-09-30 Thread Chris Angelico
On Mon, Oct 1, 2012 at 12:23 AM, Roy Smith  wrote:
> In article ,
>  Chris Angelico  wrote:
>
>> there's no efficient and reliable way to change/reload code in a
>> running application (not often an issue).
>
> What we do (largely cribbed from django's runserver) is start up a
> thread which once a second, looks at all the modules in sys.modules,
> checks to see if the modification time for their source files has
> changed, and if so, restarts the application.  This is hugely convenient
> when developing any kind of long-running application.  You don't need to
> keep restarting the application; just edit the source and changes take
> effect (almost) immediately.
>
> Not sure if this is what you had in mind.

It's not an _explicit_ restart, but you have to write your application
to keep all its state on disk in some way. What I'm talking about is
having a single process that never terminates, never stops accepting
connections, but at some point new connections begin to be served with
new code - with old ones, if they're still going, continuing to be
handled by the old code. I have one such process that's been going for
(let me check) 115 wk 0d 21:05:21.

For many types of application, restarting is perfectly viable, so this
isn't a major issue with Python.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can somebody give me an advice about what to learn?

2012-09-30 Thread Chris Angelico
On Mon, Oct 1, 2012 at 12:35 AM, Chris Angelico  wrote:
> What I'm talking about is
> having a single process that never terminates, never stops accepting
> connections, but at some point new connections begin to be served with
> new code...

And to clarify, only the code that needs updating gets updated;
in-memory state is retained elsewhere, and modules are permitted and
welcome to use a "global state area" that doesn't get wiped on any
code reload.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can somebody give me an advice about what to learn?

2012-09-30 Thread Roy Smith
In article ,
 Chris Angelico  wrote:

> On Mon, Oct 1, 2012 at 12:23 AM, Roy Smith  wrote:
> > In article ,
> >  Chris Angelico  wrote:
> >
> >> there's no efficient and reliable way to change/reload code in a
> >> running application (not often an issue).
> >
> > What we do (largely cribbed from django's runserver) is start up a
> > thread which once a second, looks at all the modules in sys.modules,
> > checks to see if the modification time for their source files has
> > changed, and if so, restarts the application.  This is hugely convenient
> > when developing any kind of long-running application.  You don't need to
> > keep restarting the application; just edit the source and changes take
> > effect (almost) immediately.
> >
> > Not sure if this is what you had in mind.
> 
> It's not an _explicit_ restart, but you have to write your application
> to keep all its state on disk in some way.

Well, more strictly, what you need is to keep your state somewhere else.  
Doesn't have to be on disk.  Could be in memory, if that memory belongs 
to another process (memcache, redis, or any of a number of in-memory 
databases).

> What I'm talking about is
> having a single process that never terminates, never stops accepting
> connections, but at some point new connections begin to be served with
> new code - with old ones, if they're still going, continuing to be
> handled by the old code. I have one such process that's been going for
> (let me check) 115 wk 0d 21:05:21.

Why does it have to be a single process?  I could imagine some front-end 
process which accepts connections and hands them off to worker 
processes.  When you install new code, you could do it in a different 
directory tree, and then signal the front end that new code exists.  The 
front end could then {chdir, munge sys.path, whatever} to the root of 
the new tree and keep going.  Existing connections stay up with the old 
code, new connections get the new code.

If you didn't want to fork a new process every time, you could have a 
worker process pool.  When a worker signaled it was done with a task, 
the front end could either assign it a new connection (if the code it 
was running was still current), or kill it off if it was running stale 
code.

If you truly needed this to be a single process, I could imagine a 
customized module importer which altered the module name to include a 
version prefix before registering it in sys.modules.  I think that could 
be made to work, but would be really ugly and complicated.  Or elegant 
and nifty, depending on your attitude :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can somebody give me an advice about what to learn?

2012-09-30 Thread rusi
On Sep 30, 5:58 pm, tcgo  wrote:
> Hi!
> I'm really new to Usenet/Newsgroups, but... I'd like to learn some new 
> programming language, because I learnt a bit of Perl though its OOP is ugly. 
> So, after searching a bit, I found Python and Ruby, and both of they are cute.
> So, assuming you'll say me "learn python", why should I learn it over Ruby?
> Thanks!
> PS: I don't want to start a flame-war, I just want an advice if it's possible 
> please!

Here's a test to help you decide: How do you respond to the word
'magic'?
If positive you will like Ruby, if not you may prefer Python.

Personal note: I like magic -- as long as its not in a tech area, eg
I'm a fan of Harry Potter.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can somebody give me an advice about what to learn?

2012-09-30 Thread Chris Angelico
On Mon, Oct 1, 2012 at 1:01 AM, Roy Smith  wrote:
> Well, more strictly, what you need is to keep your state somewhere else.
> Doesn't have to be on disk.  Could be in memory, if that memory belongs
> to another process (memcache, redis, or any of a number of in-memory
> databases).

Sure. I'll generalize my statement to "Has to be external to the
process". That generally precludes the direct use of complex objects,
requiring some form of serialization or dump format - you can't, for
instance, retain a "socket connection object" across that sort of
reload.

> Why does it have to be a single process?  I could imagine some front-end
> process which accepts connections and hands them off to worker
> processes.  When you install new code, you could do it in a different
> directory tree, and then signal the front end that new code exists.  The
> front end could then {chdir, munge sys.path, whatever} to the root of
> the new tree and keep going.  Existing connections stay up with the old
> code, new connections get the new code.

That's also a good model, for situations that can use it. My situation
is a MUD-like system where different clients can affect one another,
so the most logical way to do it is a single process. For instance, we
have a Dungeons and Dragons battle grid that uses a web browser as its
display engine; you go to a particular URL, key in your login details,
and it sends AJAX long polls to the server. Whenever one client moves
a token on the grid, every other client gets notified. I could, of
course, do this across processes, but I'd end up needing a hefty IPC
system; this way, all I need is a lightweight event semaphore that the
threads wait on, and they look at the process's internal structures
(thread-safe, they need only read at that point). I could have done it
in other ways, of course, but this is nice and straightforward.

But this is getting rather off-topic :) For the bulk of usage
patterns, Python's fine. Most languages don't let you reload code on
the fly, and most applications are never going to be bothered by this
miniscule feature lack!

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can somebody give me an advice about what to learn?

2012-09-30 Thread Mark Lawrence

On 30/09/2012 13:58, tcgo wrote:

Hi!
I'm really new to Usenet/Newsgroups, but... I'd like to learn some new 
programming language, because I learnt a bit of Perl though its OOP is ugly. 
So, after searching a bit, I found Python and Ruby, and both of they are cute.
So, assuming you'll say me "learn python", why should I learn it over Ruby?
Thanks!
PS: I don't want to start a flame-war, I just want an advice if it's possible 
please!



http://www.gossamer-threads.com/lists/python/python/129650?do=post_view_threaded

--
Cheers.

Mark Lawrence.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Can somebody give me an advice about what to learn?

2012-09-30 Thread Joshua Landau
On 30 September 2012 13:58, tcgo  wrote:

> Hi!
> I'm really new to Usenet/Newsgroups, but... I'd like to learn some new
> programming language, because I learnt a bit of Perl though its OOP is
> ugly. So, after searching a bit, I found Python and Ruby, and both of them
> are cute.
> So, assuming you'll say me "learn python", why should I learn it over Ruby?
> Thanks!
> PS: I don't want to start a flame-war, I just want an advice if it's
> possible please!
>

Like the others I don't know Ruby but a 2 minute check on Google implies
that Ruby doesn't have something equivalent to Cython.

I *really like* Cython because it lets me optimize without learning
C*. I *really
dislike* C, so this is important to me. Cython may be a bit much [aka. is
way too much] for someone learning a language, but it will help if you do
progress that much further. Of course, Ruby lets you write C extensions,
but that's another language to learn.

* You still have to learn C types, but Cython has better array classes and
support for Python buffers that lets you skip most of the harder types. You
don't need malloc in Cython, for example, unless you really need C arrays.

Python also has PyPy, which is faster than most of what Ruby has, pushing
that dreaded optimization down the road.

Language wise, *whilst again I cannot speak for Ruby*, Python has a very
important trait: sanity. If you slow yourself down enough, Python has a
miraculous ability to make the meaning of every line you write *bloody
obvious*. That's pretty much the most important part of a language. *Look
over code examples of both, and choose the language you can read.*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] experimental: Misc/NEWS included in docs

2012-09-30 Thread Chris Jerdonek
On Sun, Sep 30, 2012 at 6:17 AM, Georg Brandl  wrote:
> at http://docs.python.org/3.3/whatsnew/news.html, there is now
> a rendering of Misc/NEWS with tracker links and a crude filtering
> capability.  I thought that this will complement the "whatsnew"
> documents nicely for people looking for more detail.
>
> Please let me know if it's useful, or what could be done to make
> it *more* useful.

Good idea.  Some suggestions:

* A note at the top explaining what this page is and how it differs
from the other What's New page (including perhaps a link to the other
What's New page).  It might also be good if the two had more
distinctive titles.  They are currently "What’s New in Python" and
"Python News."

* It would be good if the section links could somehow be
"perma-links."  They will currently vary over time, e.g.
  http://docs.python.org/py3k/whatsnew/news.html#id3

* Lastly, I think skimming this list would be more informative to me
at least if each bullet began with the name of the affected module or
area (at least in the case where just one module is affected).  The
issue number is less meaningful as a descriptive header.  Changing
this would likely require changes in how we prepare Misc/NEWS though.

On a separate but related note, I never know where to put the various
subsections in relation to one another in Misc/NEWS (Core and
Builtins, Library, Extension Modules, etc).  It would be good if there
was guidance on that -- even if to say it completely doesn't matter.

--Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


Coexistence of Python 2.x and 3.x on same OS

2012-09-30 Thread Edward Diener
Has there been any official software that allows both the Python 2.x and 
3.x releases to coexist on the same OS so that the end-user can easily 
switch between them when invoking Python scripts after each has been 
installed to their own directories/folders ?


I know of some unoffical solutions, but they require lots of tweaks. 
Given the vagaries of the different OSs on which Python can run I am 
hoping for some offical solution which will work on any of the most 
popular OSs ( Windows, Linux, Mac ).


The situation is so confusing on Windows, where the file associations, 
registry entries, and other internal software which allows a given 
Python release to work properly when invoking Python is so complicated, 
that I have given up on trying to install more than one Python release 
and finding a relaible, foolproof way of switching between them. So 
although I would like to use the latest 3.x series on Windows I have 
decide to stick with the latest 2.x series instead because much software 
using Python does not support 3.x yet.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Coexistence of Python 2.x and 3.x on same OS

2012-09-30 Thread Andrew Berg
On 2012.09.30 14:14, Edward Diener wrote:
> The situation is so confusing on Windows, where the file associations, 
> registry entries, and other internal software which allows a given 
> Python release to work properly when invoking Python is so complicated, 
> that I have given up on trying to install more than one Python release 
> and finding a relaible, foolproof way of switching between them. So 
> although I would like to use the latest 3.x series on Windows I have 
> decide to stick with the latest 2.x series instead because much software 
> using Python does not support 3.x yet.

http://www.python.org/dev/peps/pep-0397/

Unix-based OSes should already obey the shebang line, and on Windows,
there's py.exe in 3.3 that will launch the intended version based on
that shebang line. While I was using the alpha/beta versions of 3.3, I
had no problems invoking either 3.2 or 3.3 with the shebang line on Windows.
-- 
CPython 3.3.0 | Windows NT 6.1.7601.17835
-- 
http://mail.python.org/mailman/listinfo/python-list


Can't import modules

2012-09-30 Thread Peter Farrell
Hello!

I'm still new to Python, so here's another easy one. After I save something 
I've done as a .py file, how do I import it into something else I work on? 
Every time I try to import something other than turtle or math, I get this 
error message:

'module' object is not callable

What am I doing wrong?

Thanks!

Peter Farrell
San Mateo, CA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't import modules

2012-09-30 Thread Benjamin Kaplan
On Sun, Sep 30, 2012 at 12:42 PM, Peter Farrell
 wrote:
> Hello!
>
> I'm still new to Python, so here's another easy one. After I save something 
> I've done as a .py file, how do I import it into something else I work on? 
> Every time I try to import something other than turtle or math, I get this 
> error message:
>
> 'module' object is not callable
>
> What am I doing wrong?
>
> Thanks!
>
> Peter Farrell
> San Mateo, CA
> --

Well, you haven't told us what you're doing, so it's hard to say what
you're doing wrong. So I'm going to make a few guesses.

1. Your first (and possibly only other) language was Java.
2. You're making a class (let's say Foo) and putting it in a file of
the same name (Foo.py)
3. You're doing "import Foo" and then calling "Foo()" trying to
instantiate the class.

Python doesn't have that "one class per file, and the file must have
the same name as the class" rule as Java. The file defines a module,
which is an object and can have any number of objects (including
classes, because those are objects too) in it.

$ cat foo.py
class Foo(object):
pass

def add2(y) :
return y + 2
bkaplan:~ bkaplan$ python
Python 2.7.3 (default, Apr 23 2012, 10:06:17)
[GCC 4.2.1 Compatible Apple Clang 3.1 (tags/Apple/clang-318.0.58)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import foo
>>> dir(foo)
['Foo', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', 'add2', 'x']
>>> foo()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'module' object is not callable
>>> foo.Foo()

>>> foo.add2(5)
7
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't import modules

2012-09-30 Thread Steven D'Aprano
On Sun, 30 Sep 2012 12:42:37 -0700, Peter Farrell wrote:

> Hello!
> 
> I'm still new to Python, so here's another easy one. After I save
> something I've done as a .py file, how do I import it into something
> else I work on? Every time I try to import something other than turtle
> or math, I get this error message:
> 
> 'module' object is not callable
> 
> What am I doing wrong?


I would say that the two things you are doing wrong are, firstly, not 
posting the ENTIRE error message, including the full traceback, and most 
importantly, not paying attention to what Python is trying to tell you.

The full traceback gives import information. For example:

py> import foo
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named 'foo'


Note carefully that Python tells you the *kind* of error made: an IMPORT 
error, as well as a specific error message, namely that there is no 
module called "foo". Python will often print the actual line causing the 
error as well.

In your case, my guess is that this is your error:

py> import math
py> math(123)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'module' object is not callable


Notice that the import succeeds. So it is *incorrect* that you cannot 
import modules, but once you import them, you use them incorrectly! 
Python tells you exactly what went wrong, if you would only pay attention 
to it:

* it is a TYPE error, not an import error;
* modules cannot be called as if they were a function


Does this solve your problem?

If not, please:

* show us the ACTUAL code you are using
* show us the full traceback, not just the error message
* and don't expect us to guess what you are doing


Thank you.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't import modules

2012-09-30 Thread Steven D'Aprano
On Sun, 30 Sep 2012 12:42:37 -0700, Peter Farrell wrote:

> Hello!
> 
> I'm still new to Python, so here's another easy one. After I save
> something I've done as a .py file, how do I import it into something
> else I work on? Every time I try to import something other than turtle
> or math, I get this error message:
> 
> 'module' object is not callable
> 
> What am I doing wrong?


I would say that the two things you are doing wrong are, firstly, not 
posting the ENTIRE error message, including the full traceback, and most 
importantly, not paying attention to what Python is trying to tell you.

The full traceback gives import information. For example:

py> import foo
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named 'foo'


Note carefully that Python tells you the *kind* of error made: an IMPORT 
error, as well as a specific error message, namely that there is no 
module called "foo". Python will often print the actual line causing the 
error as well.

In your case, my guess is that this is your error:

py> import math
py> math(123)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'module' object is not callable


Notice that the import succeeds. So it is *incorrect* that you cannot 
import modules, but once you import them, you use them incorrectly! 
Python tells you exactly what went wrong, if you would only pay attention 
to it:

* it is a TYPE error, not an import error;
* modules cannot be called as if they were a function


Does this solve your problem?

If not, please:

* show us the ACTUAL code you are using
* show us the full traceback, not just the error message
* and don't expect us to guess what you are doing


Thank you.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't import modules

2012-09-30 Thread Hans Mulder
On 30/09/12 21:42:37, Peter Farrell wrote:
> I'm still new to Python, so here's another easy one. After I save something
> I've done as a .py file, how do I import it into something else I work on?
> Every time I try to import something other than turtle or math, I get this 
> error message:
> 
> 'module' object is not callable
> 
> What am I doing wrong?

For starters, you're not showing us any code.

The error message suggests that you have successfully imported
a module, and you then try to use the module as if it were a
callable.  That won't work: modules are not callable.

My crystal ball says that you may have been a Java programmer
in an earlier life.  In Java, a file must define exactly one
class, and the class must have the same name as the file.

Python is not Java.  In Python, a file may define one class,
or twenty, or none at all.  To avoid confusion, do not give
any of your classes the same name as any of your files.


Hope this helps,

-- HansM


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compairing filenames in a list

2012-09-30 Thread Arnaud Delobelle
On 30 September 2012 02:27, Kevin Anthony  wrote:
> I have a list of filenames, and i need to find files with the same name,
> different extensions, and split that into tuples.  does anyone have any
> suggestions on an easy way to do this that isn't O(n^2)?

>>> import os, itertools
>>> filenames = ["foo.png", "bar.csv", "foo.html", "bar.py"]
>>> dict((key, tuple(val)) for key, val in itertools.groupby(sorted(filenames), 
>>> lambda f: os.path.splitext(f)[0]))
{'foo': ('foo.html', 'foo.png'), 'bar': ('bar.csv', 'bar.py')}

-- 
Arnaud
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can somebody give me an advice about what to learn?

2012-09-30 Thread Roy Smith
In article ,
 Chris Angelico  wrote:

> you can't, for instance, retain a "socket connection object" across 
> that sort of reload.

Yeah, that's a problem.  There's nothing fundamental about a TCP 
connection endpoint which precludes it being serialized and passed 
around.  The amount of state involved is pretty small.  Unless I've 
forgotten something, 2 IP addresses, 2 port numbers, a few bits worth of 
TCP protocol state, and, for open connections, 2 sequence numbers.  
Maybe a couple of timers, but I don't think they're strictly necessary.  
The problem is, most of that state is private to the kernel.

On the other hand, you could do what "screen" does, and spawn a process 
per connection to hold the connection open :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can somebody give me an advice about what to learn?

2012-09-30 Thread Roy Smith
In article 
<4806a0b7-818a-4844-8286-f1b891a3c...@rj6g2000pbc.googlegroups.com>,
 rusi  wrote:

> Here's a test to help you decide: How do you respond to the word 
> 'magic'?  If positive you will like Ruby, if not you may prefer 
> Python.

Some might say that magic underscores a lot of the really fun stuff in 
Python.  See http://www.rafekettler.com/magicmethods.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can somebody give me an advice about what to learn?

2012-09-30 Thread Chris Angelico
On Mon, Oct 1, 2012 at 8:14 AM, Roy Smith  wrote:
> Yeah, that's a problem.  There's nothing fundamental about a TCP
> connection endpoint which precludes it being serialized and passed
> around.  The amount of state involved is pretty small.  Unless I've
> forgotten something, 2 IP addresses, 2 port numbers, a few bits worth of
> TCP protocol state, and, for open connections, 2 sequence numbers.
> Maybe a couple of timers, but I don't think they're strictly necessary.
> The problem is, most of that state is private to the kernel.

And can change at a moment's notice, with no userspace interaction.
The socket connection also needs to retain sent-but-not-acknowledged
and received-but-not-in-order data, so those buffers need to exist.
The only way would be for the kernel to export something representing
a socket - which would be the file handle.

And then you have to worry about any other state, eg if you're reading
line by line and are retaining a partial line... not really something
that can be patched in five seconds, and not IMHO worth trying to do.
Easier to simply retain the process ID.

Oh, and if the pid changes on a live connection, what will that do
with iptables controls, which can look at the originating process's
user id and such? Hrm.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can somebody give me an advice about what to learn?

2012-09-30 Thread Steven D'Aprano
On Sun, 30 Sep 2012 18:17:17 -0400, Roy Smith wrote:

> In article
> <4806a0b7-818a-4844-8286-f1b891a3c...@rj6g2000pbc.googlegroups.com>,
>  rusi  wrote:
> 
>> Here's a test to help you decide: How do you respond to the word
>> 'magic'?  If positive you will like Ruby, if not you may prefer Python.
> 
> Some might say that magic underscores a lot of the really fun stuff in
> Python.  See http://www.rafekettler.com/magicmethods.html

And they would be wrong.

The word they want is "special", not magic. There's nothing[1] magic 
about double leading-and-trailing underscore methods. They are just 
ordinary methods that are treated specially by Python to implement syntax 
such as + (the __add__ and __radd__ methods), len() (the __len__ method) 
and similar.

The article you link to starts off with this:

[quote]
What are magic methods? They're everything in object-oriented
Python. They're special methods that you can define to add 
"magic" to your classes.
[end quote]

Being able to add two values, or get the number of items in a container, 
is hardly magic. They're *special*, because the compiler looks for 
methods of those names, but that's all.

[quote]
They're also not as well documented as they need to be. All of 
the magic methods for Python appear in the same section in the 
Python docs, but they're scattered about and only loosely organized.
[end quote]

You got that? They're all in the same section, AND they are scattered 
about at the same time! Now that's truly magic! *wink*

Special is not magic. Magic means that the normal behaviour of the 
language is broken for some arbitrary cases. Here's an example in 
hardware of "magic":

http://catb.org/jargon/html/magic-story.html

Now imagine that in software: it can't possibly work, and yet it does.

I dare say nearly all non-toy languages have *some* magic. But some 
languages have more than others: they are full of unique cases, every one 
different, where the same code behaves differently that you would expect. 
There *is* some magic in Python:

* Methods and attributes that start with a double underscore, but do not
  end with a double underscore, have their name mangled by the compiler.
  So your source code says "MyClass.__method", but the method actually
  created is "MyClass.__MyClass_method".

 This is magic because __names everywhere else do not work that way,
 nor do names that don't start with double-underscores.

* In Python 3, if you call super() with no arguments inside a class, 
  the compiler runs some voodoo to determine the class it belongs to 
  and the instance it is called from. Outside of a class, super() 
  with no arguments behaves like any other function.

  This is magic because the normal behaviour of a function with two
  required arguments is to fail if you don't provide the arguments.
  But super() can, somehow, determine the arguments itself, partially
  at compile-time and partially at run-time.

* The relationship between built-ins type() and object() is magic. 
  object is a type. But type is itself an object. You can't define
  object until type exists, and you can't define type until object
  exists. But the compiler magically bootstraps them into existence.

  This is magic because it is impossible[2] for pure Python code to
  bootstrap such mutually-defined types into existence.

Off the top of my head, I can't really think of anything else that is 
magic in Python.

Note that individual uses of magic are generally done for good reasons, 
or at least what seems like a good reason. For example, super's magic 
class detection is useful and prevents bugs. But *in general* magic is a 
bad thing, because it makes the language incomprehensible and code 
surprising. Languages with a lot of magic tend towards code which is hard 
to maintain and debug.

Note also that "magic" is different from "deep magic" and "black magic":

http://catb.org/jargon/html/M/magic.html




[1] Perhaps not quite *nothing*, arguably there is a *tiny* bit of magic 
in that Python bypasses the instance when looking up __dunder__ methods 
as a speed optimization. But that's more like a sprinkle of fairy dust 
than real magic.

[2] Or at least tricky and messy.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


parse an environment file

2012-09-30 Thread Jason Friedman
$ crontab -l
* * * * * env

This produces mail with the following contents:

HOME=/home/spjsf
LOGNAME=spjsf
PATH=/usr/bin:/bin
PWD=/home/spjsf
SHELL=/bin/sh
SHLVL=1
USER=spjsf
_=/usr/bin/env

On the other hand

$ env

produces about 100 entries, most of which are provided by my .bashrc;
cron provides only a limited number of environment variables.

I want my python 3.2.2 script, called via cron, to know what those
additional variables are.  How?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't import modules

2012-09-30 Thread Peter Farrell
Thanks for trying to help, everybody. Sorry I didn't post the whole error 
message. Now my problem is I just installed VPython and I'm trying to run the 
very first example, bounce.py which I located. I opened it and ran it in Idle. 
I got this message:

Traceback (most recent call last):
  File "C:\Python32\Lib\site-packages\visual\examples\bounce.py", line 1, in 

from visual import *
  File "C:\Python32\lib\site-packages\visual\__init__.py", line 1, in 
from .visual_all import *
  File "C:\Python32\lib\site-packages\visual\visual_all.py", line 1, in 
from vis import version
  File "C:\Python32\lib\site-packages\vis\__init__.py", line 3, in 
from .cvisual import (vector, dot, mag, mag2, norm, cross, rotate,
SystemError: initialization of cvisual raised unreported exception

I'm not a programmer, just a math teacher/tutor who's trying to teach my 
students to understand math through using something real like Python. I'll keep 
you posted on my progress.

Thank you in advance for your help!

Peter

On Sunday, September 30, 2012 1:22:31 PM UTC-7, Hans Mulder wrote:
> On 30/09/12 21:42:37, Peter Farrell wrote:
> 
> > I'm still new to Python, so here's another easy one. After I save something
> 
> > I've done as a .py file, how do I import it into something else I work on?
> 
> > Every time I try to import something other than turtle or math, I get this 
> > error message:
> 
> > 
> 
> > 'module' object is not callable
> 
> > 
> 
> > What am I doing wrong?
> 
> 
> 
> For starters, you're not showing us any code.
> 
> 
> 
> The error message suggests that you have successfully imported
> 
> a module, and you then try to use the module as if it were a
> 
> callable.  That won't work: modules are not callable.
> 
> 
> 
> My crystal ball says that you may have been a Java programmer
> 
> in an earlier life.  In Java, a file must define exactly one
> 
> class, and the class must have the same name as the file.
> 
> 
> 
> Python is not Java.  In Python, a file may define one class,
> 
> or twenty, or none at all.  To avoid confusion, do not give
> 
> any of your classes the same name as any of your files.
> 
> 
> 
> 
> 
> Hope this helps,
> 
> 
> 
> -- HansM
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parse an environment file

2012-09-30 Thread Dave Angel
On 09/30/2012 08:11 PM, Jason Friedman wrote:

First comment:  I don't know anything about an "environment file."  An
environment is an attribute of a process, and it's inherited by
subprocesses that process launches.  This is not a Python thing, it's an
OS thing, for whatever OS you're running.

> $ crontab -l
> * * * * * env
>
> This produces mail with the following contents:
>
> HOME=/home/spjsf
> LOGNAME=spjsf
> PATH=/usr/bin:/bin
> PWD=/home/spjsf
> SHELL=/bin/sh
> SHLVL=1
> USER=spjsf
> _=/usr/bin/env

In other words, these are the environment variables that cron has, and
that it gives to any children it launches.

> On the other hand
>
> $ env
>
> produces about 100 entries, most of which are provided by my .bashrc;
> cron provides only a limited number of environment variables.

Gee, those are variables specific to a particular (bash) shell, so how
would a program launched by cron know about them?


> I want my python 3.2.2 script, called via cron, to know what those
> additional variables are.  How?

You'd have to change the environment that cron sees (before login), or
add to the crontab, or /etc/default/cron, or else run some shell from
cron that defines those variables and then runs the application.  The
way to do this is specific to whatever OS you're running, and is
irrelevant to Python.

Try googling.  For some examples, none of which use Python:

http://www.perlmonks.org/?node_id=624540
http://www.unix.com/solaris/164483-environment-variables-cron.html
http://www.computing.net/answers/unix/how-to-set-environment-variable/5689.html
http://linuxshellaccount.blogspot.com/2007/10/crontab-and-your-environment.html

-- 

DaveA

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Slicing iterables in sub-generators without loosing elements

2012-09-30 Thread 88888 Dihedral
On Sunday, September 30, 2012 12:15:57 AM UTC+8, Thomas Bach wrote:
> Hi,
> 
> 
> 
> say we have the following:
> 
> 
> 
> >>> data = [('foo', 1), ('foo', 2), ('bar', 3), ('bar', 2)]
> 
> 
> 
> is there a way to code a function iter_in_blocks such that
> 
> 
> 
> >>> result = [ list(block) for block in iter_in_blocks(data) ]
> 
> 
> 
> evaluates to
> 
> 
> 
> >>> result = [ [('foo', 1), ('foo', 2)], [('bar', 3), ('bar', 2)] ]
> 
> 
> 
> by _only_ _iterating_ over the list (caching all the elements sharing
> 
> the same first element doesn't count)?
> 
> 
> 
> I came up with the following
> 
> 
> 
> def iter_in_blocks(iterable):
> 
> my_iter = iter(iterable)
> 
> while True:
> 
> first = next(my_iter)
> 
> pred = lambda entry: entry[0] == first[0]
> 
> def block_iter():
> 
> yield first
> 
> for entry in itertools.takewhile(pred, my_iter):
> 
> yield entry
> 
> yield block_iter()
> 
> 
> 
> which does not work as itertools.takewhile consumes the first entry
> 
> not fulfilling the pred.
> 
> 
> 
> I currently have the intuition that the problem is not solvable
> 
> without using e.g. a global to pass something back to iter_in_blocks
> 
> from block_iter. Any other suggestions?
> 
> 
> 
> Regards,
> 
>   Thomas Bach.

Your question seems vague to me. If you know you are storing 
only immutable tuples in a list, then the way to iterate is simple. 

For example: 

data = [('foo', 1), ('foo', 2), ('bar', 3), ('bar', 2)] 
# all tuples 

for item in data: 
x1=item[0] # first entry in each tuple
x2=item[1]
print x1, x2 # or use yield in a function to iterate



 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't import modules

2012-09-30 Thread Dave Angel
On 09/30/2012 08:35 PM, Peter Farrell wrote:

You top-posted, which means there's no context;  the message is now out
of order.  Please put your responses after the parts you're quoting, or
don't bother quoting.

> Thanks for trying to help, everybody. Sorry I didn't post the whole error 
> message. Now my problem is I just installed VPython and I'm trying to run the 
> very first example, bounce.py which I located. I opened it and ran it in 
> Idle. I got this message:
>
> Traceback (most recent call last):
>   File "C:\Python32\Lib\site-packages\visual\examples\bounce.py", line 1, in 
> 
> from visual import *
>   File "C:\Python32\lib\site-packages\visual\__init__.py", line 1, in 
> from .visual_all import *
>   File "C:\Python32\lib\site-packages\visual\visual_all.py", line 1, in 
> 
> from vis import version
>   File "C:\Python32\lib\site-packages\vis\__init__.py", line 3, in 
> from .cvisual import (vector, dot, mag, mag2, norm, cross, rotate,
> SystemError: initialization of cvisual raised unreported exception

That's a different error message than you reported at first.  If you
can't even run an example supplied with the system, you'd better post a
question on the vpython forum (I presume it's available from
http://vpython.wikidot.com/system:join)   Presumably the install program
is broken.  Or maybe you just can't run visual from IDLE.  Try running
from the terminal prompt.

I'm amazed that it uses   the form:from visual_all import *
That's considered bad form.  Still, it's probably not the problem.  What
happens if you write a two line program:
import visual_all
print("Import succeeded")


> I'm not a programmer, just a math teacher/tutor who's trying to teach my 
> students to understand math through using something real like Python. I'll 
> keep you posted on my progress.
>
> Thank you in advance for your help!
>
>

-- 

DaveA

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parse an environment file

2012-09-30 Thread Steven D'Aprano
On Sun, 30 Sep 2012 18:11:09 -0600, Jason Friedman wrote:

> $ crontab -l
> * * * * * env
> 
> This produces mail with the following contents:
[snip]

Yes, env returns the environment variables of the current environment.


> On the other hand
> 
> $ env
> 
> produces about 100 entries, most of which are provided by my .bashrc;
> cron provides only a limited number of environment variables.

That's because it's a different environment.

 
> I want my python 3.2.2 script, called via cron, to know what those
> additional variables are.  How?

In general, you can't, because they may not even exist when your script 
runs. There's no guarantee that "your environment" (which one? you might 
have many, or none) exists at the time, and env certainly cannot guess 
which one that might be.

But specifically, if you know the ID of a process, you may be able to see 
that process' environment variables by reading the /proc//environ 
virtual file, which is a NULL-delimited list of environment variables.

As usual, permissions apply. In general, you can read your own processes, 
but not those of other users.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't import modules

2012-09-30 Thread Joshua Landau
On 1 October 2012 01:35, Peter Farrell  wrote:

> Thanks for trying to help, everybody. Sorry I didn't post the whole error
> message. Now my problem is I just installed VPython and I'm trying to run
> the very first example, bounce.py which I located. I opened it and ran it
> in Idle. I got this message:
>
> Traceback (most recent call last):
>   File "C:\Python32\Lib\site-packages\visual\examples\bounce.py", line 1,
> in 
> from visual import *
>   File "C:\Python32\lib\site-packages\visual\__init__.py", line 1, in
> 
> from .visual_all import *
>   File "C:\Python32\lib\site-packages\visual\visual_all.py", line 1, in
> 
> from vis import version
>   File "C:\Python32\lib\site-packages\vis\__init__.py", line 3, in 
> from .cvisual import (vector, dot, mag, mag2, norm, cross, rotate,
> SystemError: initialization of cvisual raised unreported exception
>
> I'm not a programmer, just a math teacher/tutor who's trying to teach my
> students to understand math through using something real like Python. I'll
> keep you posted on my progress.
>
> Thank you in advance for your help!


Please don't top post .

Are you using Ubuntu, by chance? If you are, try looking at the VPython
archives ,
specifically 
this.
I chose that because although I know almost nothing about VPython it is
recent. Try VPython's list even if it isn't as they're likely to know more
than us.

Also, this error is distinctly different to the one you first posted. What
happened there?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't import modules

2012-09-30 Thread Steven D'Aprano
On Sun, 30 Sep 2012 17:35:02 -0700, Peter Farrell wrote:

> Thanks for trying to help, everybody. Sorry I didn't post the whole
> error message. Now my problem is I just installed VPython and I'm trying
> to run the very first example, bounce.py which I located. I opened it
> and ran it in Idle. I got this message:

In general, any time you get unexpected or unusual errors in IDLE, you 
should try running the same code without IDLE, just at the regular Python 
prompt. Like all "Integrated Development Environments", IDLE sometimes 
messes about with things in the background that very occasionally 
interferes with the normal running of certain Python code, so it is 
always worth taken IDLE out of the picture whenever there is a mysterious 
failure. 

In Windows, I *think* that if you run "python" (or perhaps "python32") 
from the Start Menu, it will open an interactive prompt similar to IDLE. 
Once the Python interactive interpreter has launched, just enter:

from visual import *

and see if it works. If it fails, try:

import visual


My wild guess is that VPython (whatever that is!) only works under Python 
2, not Python 3, but I could be wrong.

Other than that, my advice is to check with a dedicated VPython mailing 
list. Oh, and if you do find the solution, please consider reporting what 
the solution is back here, for the benefit of the next person who runs 
into this issue.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't import modules

2012-09-30 Thread Peter Farrell
On Sunday, September 30, 2012 6:25:29 PM UTC-7, Steven D'Aprano wrote:
> On Sun, 30 Sep 2012 17:35:02 -0700, Peter Farrell wrote:
> 
> 
> 
> > Thanks for trying to help, everybody. Sorry I didn't post the whole
> 
> > error message. Now my problem is I just installed VPython and I'm trying
> 
> > to run the very first example, bounce.py which I located. I opened it
> 
> > and ran it in Idle. I got this message:
> 
> 
> 
> In general, any time you get unexpected or unusual errors in IDLE, you 
> 
> should try running the same code without IDLE, just at the regular Python 
> 
> prompt. Like all "Integrated Development Environments", IDLE sometimes 
> 
> messes about with things in the background that very occasionally 
> 
> interferes with the normal running of certain Python code, so it is 
> 
> always worth taken IDLE out of the picture whenever there is a mysterious 
> 
> failure. 
> 
> 
> 
> In Windows, I *think* that if you run "python" (or perhaps "python32") 
> 
> from the Start Menu, it will open an interactive prompt similar to IDLE. 
> 
> Once the Python interactive interpreter has launched, just enter:
> 
> 
> 
> from visual import *
> 
> 
> 
> and see if it works. If it fails, try:
> 
> 
> 
> import visual
> 
> 
> 
> 
> 
> My wild guess is that VPython (whatever that is!) only works under Python 
> 
> 2, not Python 3, but I could be wrong.
> 
> 
> 
> Other than that, my advice is to check with a dedicated VPython mailing 
> 
> list. Oh, and if you do find the solution, please consider reporting what 
> 
> the solution is back here, for the benefit of the next person who runs 
> 
> into this issue.
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Steven

Thanks again for the help. I entered the import statements you suggested into 
the Python Shell and they gave me the same error message. (Neither did 
visual_all, but of course the print statement worked.)

Since I use Python 3.2.3 I've had trouble with programs and modules designed 
for Python 2 and many programs don't work on my 64-bit system.

I was hoping it was a common error that newbies encounter.

Thanks again, Python fans. I'll keep you posted on my progress!

Peter 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compairing filenames in a list

2012-09-30 Thread Joshua Landau
On 30 September 2012 23:08, Arnaud Delobelle  wrote:

> On 30 September 2012 02:27, Kevin Anthony 
> wrote:
> > I have a list of filenames, and i need to find files with the same name,
> > different extensions, and split that into tuples.  does anyone have any
> > suggestions on an easy way to do this that isn't O(n^2)?
>
> >>> import os, itertools
> >>> filenames = ["foo.png", "bar.csv", "foo.html", "bar.py"]
> >>> dict((key, tuple(val)) for key, val in
> itertools.groupby(sorted(filenames), lambda f: os.path.splitext(f)[0]))
> {'foo': ('foo.html', 'foo.png'), 'bar': ('bar.csv', 'bar.py')}
>

That seems wasteful. Sort is O(n log n)

I've seen this pattern a lot. Surely there should be an object for this...

filenames = ["foo.png", "bar.csv", "foo.html", "bar.py"]
>
> import os
>
> from collections import defaultdict
> grouped = defaultdict(list)
>
> for file in filenames:
> splitname = os.path.splitext(file)
> grouped[splitname[0]].append(splitname[1])
>
> grouped
> >>> defaultdict(, {'foo': ['.png', '.html'], 'bar': ['.csv',
> '.py']})


This should be near-enough O(n) time. Pah, it's not like you need to
optimize this anyway!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't import modules

2012-09-30 Thread Steven D'Aprano
On Sun, 30 Sep 2012 18:35:50 -0700, Peter Farrell wrote:

> Since I use Python 3.2.3 I've had trouble with programs and modules
> designed for Python 2 and many programs don't work on my 64-bit system.

While Python tries very hard to be backward compatible, the transition 
from the 2.x series to the 3.x series was intentionally allowed to break 
backward compatibility in certain areas.

If VPython only supports 2.x, you should ask the vendors to support at 
least 3.3 or better, preferably the full 3.x series. In the meantime, you 
may have to stick to the 2.x series.


> I was hoping it was a common error that newbies encounter.

Trying to run Python 2.x code in 3.x? Yes, that's common. Trying to run 
VPython? Not so much.

Good luck!


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't import modules

2012-09-30 Thread Steven D'Aprano
On Sun, 30 Sep 2012 18:35:50 -0700, Peter Farrell wrote:

> Since I use Python 3.2.3 I've had trouble with programs and modules
> designed for Python 2 and many programs don't work on my 64-bit system.

While Python tries very hard to be backward compatible, the transition 
from the 2.x series to the 3.x series was intentionally allowed to break 
backward compatibility in certain areas.

If VPython only supports 2.x, you should ask the vendors to support at 
least 3.3 or better, preferably the full 3.x series. In the meantime, you 
may have to stick to the 2.x series.


> I was hoping it was a common error that newbies encounter.

Trying to run Python 2.x code in 3.x? Yes, that's common. Trying to run 
VPython? Not so much.

Good luck!


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't import modules

2012-09-30 Thread Dwight Hutto
On Sun, Sep 30, 2012 at 10:15 PM, Steven D'Aprano
 wrote:
> On Sun, 30 Sep 2012 18:35:50 -0700, Peter Farrell wrote:
>
>> Since I use Python 3.2.3 I've had trouble with programs and modules
>> designed for Python 2 and many programs don't work on my 64-bit system.
>
> While Python tries very hard to be backward compatible, the transition
> from the 2.x series to the 3.x series was intentionally allowed to break
> backward compatibility in certain areas.
>
> If VPython only supports 2.x,

Naw , that's your job, plus maybe looking through the python code for
Vpython, and adding a little "from __future__ import *"
you should ask the vendors to support at
> least 3.3 or better, preferably the full 3.x series. In the meantime, you
> may have to stick to the 2.x series.
>
>
>> I was hoping it was a common error that newbies encounter.
>
> Trying to run Python 2.x code in 3.x? Yes, that's common. Trying to run
> VPython? Not so much.
>
> Good luck!
>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't import modules

2012-09-30 Thread Dwight Hutto
Plus from What's New From Python 3", which are things you should be
able to change comes:

http://docs.python.org/release/3.0.1/whatsnew/3.0.html

Change the module yourself.


-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coexistence of Python 2.x and 3.x on same OS

2012-09-30 Thread Edward Diener

On 9/30/2012 3:38 PM, Andrew Berg wrote:

On 2012.09.30 14:14, Edward Diener wrote:

The situation is so confusing on Windows, where the file associations,
registry entries, and other internal software which allows a given
Python release to work properly when invoking Python is so complicated,
that I have given up on trying to install more than one Python release
and finding a relaible, foolproof way of switching between them. So
although I would like to use the latest 3.x series on Windows I have
decide to stick with the latest 2.x series instead because much software
using Python does not support 3.x yet.


http://www.python.org/dev/peps/pep-0397/

Unix-based OSes should already obey the shebang line, and on Windows,
there's py.exe in 3.3 that will launch the intended version based on
that shebang line.


The problem with that is that one has to already being using 3.3 to use 
this facility. I was hoping for a solution which was backwards 
compatible with Python 2.x.


My thought is a program distributed by Python which finds the versions 
of Python on an OS, lets the end-user choose which version should be 
invoked when Python is invoked, and does whatever is necessary to make 
that version the default version.



While I was using the alpha/beta versions of 3.3, I
had no problems invoking either 3.2 or 3.3 with the shebang line on Windows.


That does not solve the problem for Python 2.x distributions.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Can't import modules

2012-09-30 Thread Dwight Hutto
On Sun, Sep 30, 2012 at 10:48 PM, Dwight Hutto  wrote:
> Plus from What's New From Python 3", which are things you should be
> able to change comes:
>
> http://docs.python.org/release/3.0.1/whatsnew/3.0.html
>
> Change the module yourself.
>
>

And, of course:

http://docs.python.org/library/2to3.html

-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't import modules

2012-09-30 Thread Dave Angel
On 09/30/2012 09:35 PM, Peter Farrell wrote:
> On Sunday, September 30, 2012 6:25:29 PM UTC-7, Steven D'Aprano wrote:
>> On Sun, 30 Sep 2012 17:35:02 -0700, Peter Farrell wrote:
>>
>>
>>
>>> Thanks for trying to help, everybody. Sorry I didn't post the whole
>>> error message. Now my problem is I just installed VPython and I'm trying
>>> to run the very first example, bounce.py which I located. I opened it
>>> and ran it in Idle. I got this message:
>>
>>
>> In general, any time you get unexpected or unusual errors in IDLE, you 
>> should try running the same code without IDLE, just at the regular Python 
>> prompt.
>> 
> Thanks again for the help. I entered the import statements you suggested into 
> the Python Shell and they gave me the same error message. (Neither did 
> visual_all, but of course the print statement worked.)

Don't run it in the Python Shell, and don't use IDLE at all.  Run your
test either at the cmd window, or from plain Python's interactive
interpreter, or maybe from VIDLE.

>From the official download page: 
http://www.vpython.org/contents/download_windows.html


  """How to run VPython

  *

Start the program editor with the "VIDLE for Python" shortcut on the
desktop
   or on the Start menu.

  *

Open an example program -- for example, bounce2.py.

  *

Press F5 to run (or use the Run menu).

"""


> Since I use Python 3.2.3 I've had trouble with programs and modules designed 
> for Python 2 and many programs don't work on my 64-bit system.
>
> I was hoping it was a common error that newbies encounter.
>
> Thanks again, Python fans. I'll keep you posted on my progress!
VPython has separate versions for Python 2.7 and 3.2  Hopefully you
downloaded the 3.2 version, since you're running it in c:\python32

Also, these are for the 32bit version of CPython.  So double-check which
one you've got installed.



-- 

DaveA

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coexistence of Python 2.x and 3.x on same OS

2012-09-30 Thread Andrew Berg
On 2012.09.30 22:06, Edward Diener wrote:
> The problem with that is that one has to already being using 3.3 to use 
> this facility. I was hoping for a solution which was backwards 
> compatible with Python 2.x.
It's a separate tool that comes with 3.3. You can install 3.3 and never
use the actual 3.3 interpreter if you wish.

> That does not solve the problem for Python 2.x distributions.
Compatibility across versions of Python is irrelevant; the launcher
doesn't execute any Python code itself.
Straight from the PEP:
> The launcher is not tied to a specific version of Python - eg., a
> launcher distributed with Python 3.3 should be capable of locating and
> executing any Python 2.x and Python 3.x version.

-- 
CPython 3.3.0 | Windows NT 6.1.7601.17835
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coexistence of Python 2.x and 3.x on same OS

2012-09-30 Thread Dave Angel
On 09/30/2012 11:06 PM, Edward Diener wrote:
> On 9/30/2012 3:38 PM, Andrew Berg wrote:
>> On 2012.09.30 14:14, Edward Diener wrote:
>>> The situation is so confusing on Windows, where the file associations,
>>> registry entries, and other internal software which allows a given
>>> Python release to work properly when invoking Python is so complicated,
>>> that I have given up on trying to install more than one Python release
>>> and finding a relaible, foolproof way of switching between them. So
>>> although I would like to use the latest 3.x series on Windows I have
>>> decide to stick with the latest 2.x series instead because much
>>> software
>>> using Python does not support 3.x yet.
>>
>> http://www.python.org/dev/peps/pep-0397/
>>
>> Unix-based OSes should already obey the shebang line, and on Windows,
>> there's py.exe in 3.3 that will launch the intended version based on
>> that shebang line.
>
> The problem with that is that one has to already being using 3.3 to
> use this facility. I was hoping for a solution which was backwards
> compatible with Python 2.x.
>
> My thought is a program distributed by Python which finds the versions
> of Python on an OS, lets the end-user choose which version should be
> invoked when Python is invoked, and does whatever is necessary to make
> that version the default version.
>
>> While I was using the alpha/beta versions of 3.3, I
>> had no problems invoking either 3.2 or 3.3 with the shebang line on
>> Windows.
>
> That does not solve the problem for Python 2.x distributions.
>

If you read the Pep, it says the launcher will work for both 2.x and 3.x
http://www.python.org/dev/peps/pep-0397/


I've read that elsewhere, but I can't see just where you would get the
necessary modules to run it with 2.x   Possibly you'd have to build it
from sources, as there are Windows binaries that get installed to the
C:\Windows directory.

-- 

DaveA

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parse an environment file

2012-09-30 Thread Chris Angelico
On Mon, Oct 1, 2012 at 10:11 AM, Jason Friedman  wrote:
> $ env
>
> produces about 100 entries, most of which are provided by my .bashrc;
> cron provides only a limited number of environment variables.
>
> I want my python 3.2.2 script, called via cron, to know what those
> additional variables are.  How?

Looking into my crystal ball, I'm wondering if perhaps what you're
asking is for your cron job to have environment variables that aren't
set by cron, ones that you can see in your bash environment. This is a
common issue (usually with $PATH), and by no means Python-specific. A
quick web search will bring up some results, for instance:

http://www.google.com/search?q=cron+environment+variables
http://duckduckgo.com/?q=cron+environment+variables
http://www.bing.com/search?q=cron+environment+variables

If this isn't what you're asking about, please consider clarifying
your question :)

Chris Angelico
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't import modules

2012-09-30 Thread Peter Farrell
On Sunday, September 30, 2012 8:19:28 PM UTC-7, Dave Angel wrote:
> On 09/30/2012 09:35 PM, Peter Farrell wrote:
> 
> > On Sunday, September 30, 2012 6:25:29 PM UTC-7, Steven D'Aprano wrote:
> 
> >> On Sun, 30 Sep 2012 17:35:02 -0700, Peter Farrell wrote:
> 
> >>
> 
> >>
> 
> >>
> 
> >>> Thanks for trying to help, everybody. Sorry I didn't post the whole
> 
> >>> error message. Now my problem is I just installed VPython and I'm trying
> 
> >>> to run the very first example, bounce.py which I located. I opened it
> 
> >>> and ran it in Idle. I got this message:
> 
> >>
> 
> >>
> 
> >> In general, any time you get unexpected or unusual errors in IDLE, you 
> 
> >> should try running the same code without IDLE, just at the regular Python 
> 
> >> prompt.
> 
> >> 
> 
> > Thanks again for the help. I entered the import statements you suggested 
> > into the Python Shell and they gave me the same error message. (Neither did 
> > visual_all, but of course the print statement worked.)
> 
> 
> 
> Don't run it in the Python Shell, and don't use IDLE at all.  Run your
> 
> test either at the cmd window, or from plain Python's interactive
> 
> interpreter, or maybe from VIDLE.
> 
> 
> 
> >From the official download page: 
> 
> http://www.vpython.org/contents/download_windows.html
> 
> 
> 
> 
> 
>   """How to run VPython
> 
> 
> 
>   *
> 
> 
> 
> Start the program editor with the "VIDLE for Python" shortcut on the
> 
> desktop
> 
>or on the Start menu.
> 
> 
> 
>   *
> 
> 
> 
> Open an example program -- for example, bounce2.py.
> 
> 
> 
>   *
> 
> 
> 
> Press F5 to run (or use the Run menu).
> 
> 
> 
> """
> 
> 
> 
> 
> 
> > Since I use Python 3.2.3 I've had trouble with programs and modules 
> > designed for Python 2 and many programs don't work on my 64-bit system.
> 
> >
> 
> > I was hoping it was a common error that newbies encounter.
> 
> >
> 
> > Thanks again, Python fans. I'll keep you posted on my progress!
> 
> VPython has separate versions for Python 2.7 and 3.2  Hopefully you
> 
> downloaded the 3.2 version, since you're running it in c:\python32
> 
> 
> 
> Also, these are for the 32bit version of CPython.  So double-check which
> 
> one you've got installed.
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> 
> 
> DaveA
Yes, I downloaded the 3.2 version but on 64-bit. None of the 32-bit Python 
programs I've installed have worked. 

VPython didn't install a VIDLE icon on my desktop. An earlier version did, but 
then it said it couldn't find the .exe file to work!

I've sent a message to the VPython groups. I'm looking forward to using this 
program, when it finally works!

Thanks again,

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "#!/usr/bin/env python" vs. "#!/usr/bin/python"?

2012-09-30 Thread Matej Cepl
On 28/09/12 12:57, Roy Smith wrote:
> But, you might as well get into the habit of 
> using the /usr/bin/env flavor because it's more flexible.

In the same manner as one's freedom-fighter is another's fundamentalist
terrorist, what's flexible could be also dangerous. E.g.,

#!/usr/bin/env python

is forbidden in the core Fedora packages
(https://fedoraproject.org/wiki/Features/SystemPythonExecutablesUseSystemPython),
because nobody is willing to risk that by some random python binary in
/usr/local/bin some core infrastructure of Fedora installations (e.g.,
yum) could be broken.

Matěj

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't import modules

2012-09-30 Thread cjgohlke
On Sunday, September 30, 2012 5:35:02 PM UTC-7, Peter Farrell wrote:
> Thanks for trying to help, everybody. Sorry I didn't post the whole error 
> message. Now my problem is I just installed VPython and I'm trying to run the 
> very first example, bounce.py which I located. I opened it and ran it in 
> Idle. I got this message:
> 
> 
> 
> Traceback (most recent call last):
> 
>   File "C:\Python32\Lib\site-packages\visual\examples\bounce.py", line 1, in 
> 
> 
> from visual import *
> 
>   File "C:\Python32\lib\site-packages\visual\__init__.py", line 1, in 
> 
> from .visual_all import *
> 
>   File "C:\Python32\lib\site-packages\visual\visual_all.py", line 1, in 
> 
> 
> from vis import version
> 
>   File "C:\Python32\lib\site-packages\vis\__init__.py", line 3, in 
> 
> from .cvisual import (vector, dot, mag, mag2, norm, cross, rotate,
> 
> SystemError: initialization of cvisual raised unreported exception
> 
> 

Works for me on win-amd64-3.2. 

Do you have the numpy package installed? The cvisual extension module uses the 
numpy C API. The SystemError is expected if numpy is not installed.

Install numpy-MKL-1.6.2.win-amd64-py3.2.‌exe from 
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy if you are using 
VPython-5.74.win-amd64-py3.2.‌exe.

Christoph

> I'm not a programmer, just a math teacher/tutor who's trying to teach my 
> students to understand math through using something real like Python. I'll 
> keep you posted on my progress.
> 
> 
> 
> Thank you in advance for your help!
> 
> 
> 
> Peter
> 
> 
> 
> On Sunday, September 30, 2012 1:22:31 PM UTC-7, Hans Mulder wrote:
> 
> > On 30/09/12 21:42:37, Peter Farrell wrote:
> 
> > 
> 
> > > I'm still new to Python, so here's another easy one. After I save 
> > > something
> 
> > 
> 
> > > I've done as a .py file, how do I import it into something else I work on?
> 
> > 
> 
> > > Every time I try to import something other than turtle or math, I get 
> > > this error message:
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 'module' object is not callable
> 
> > 
> 
> > > 
> 
> > 
> 
> > > What am I doing wrong?
> 
> > 
> 
> > 
> 
> > 
> 
> > For starters, you're not showing us any code.
> 
> > 
> 
> > 
> 
> > 
> 
> > The error message suggests that you have successfully imported
> 
> > 
> 
> > a module, and you then try to use the module as if it were a
> 
> > 
> 
> > callable.  That won't work: modules are not callable.
> 
> > 
> 
> > 
> 
> > 
> 
> > My crystal ball says that you may have been a Java programmer
> 
> > 
> 
> > in an earlier life.  In Java, a file must define exactly one
> 
> > 
> 
> > class, and the class must have the same name as the file.
> 
> > 
> 
> > 
> 
> > 
> 
> > Python is not Java.  In Python, a file may define one class,
> 
> > 
> 
> > or twenty, or none at all.  To avoid confusion, do not give
> 
> > 
> 
> > any of your classes the same name as any of your files.
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > Hope this helps,
> 
> > 
> 
> > 
> 
> > 
> 
> > -- HansM

-- 
http://mail.python.org/mailman/listinfo/python-list