NameError: name 'execfile' is not defined

2009-03-11 Thread Henrik Bechmann
Newbie issue:

I downloaded http://www.python.org/download/releases/3.0.1/ (windows
insaller), opened the interpreter, wrote a print "Hello World" program
in helloworld.py, and in the interpreter typed

execfile("helloworld.py")

Got back

NameError: name 'execfile' is not defined

(following tutorial in David Beazley's Python Essential Reference).

Is execfile not supported in 3?

Thanks,

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


Re: Why is lambda allowed as a key in a dict?

2009-03-11 Thread Lie Ryan

Terry Reedy wrote:

r wrote:

On Mar 11, 3:40 pm, Craig Allen  wrote:

On Mar 10, 1:39 pm, Paul Rubin  wrote:



Identical strings don't necessarily have the same id:


A more verbose way to put this is "Requesting a string with a value that 
 is the same an an existing string does not necessarily result in reuse 
of the existing string but mey result in creation of a new, duplicate 
string.


I'd rather go with: "All object creation will create a new object; 
except for immutable for which the object creator may choose to return 
an equivalent existing object."


Immutables are the exception.
--
http://mail.python.org/mailman/listinfo/python-list


Re: nohup and os.system

2009-03-11 Thread Cameron Simpson
On 12Mar2009 16:37, I wrote:
| With nohup, the outputs of cmd1 and cmd2 are going to the nohup.out
| file, and thus are set to block buffering. Unless cmd1 and cmd2 have
| special command line switches to get them to line buffer (or no-buffer)
| your only recourse is to attach them to terminals, thus tricking them
| into doing line buffering again. Fortunately, this is made convenient by
| the script command. For example, try changing the string "cmd1" into the
| string:
| 
|   script -a -q -f nohup.out cmd1
| 
| (You will probably need GNU script for the -f option; see "man script"
| for details, or just try it.)

This is platform dependent. You might need to change cmd1 into:

  script -a -q -f -c 'cmd1' nohup.out

and thus:

  os.system('''script -a -q -f -c 'cmd1' nohup.out''')

in your batch.py (note the differing quotes).

Anyway, see "man script" on your system for the correct invocation.

Cheers,
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

A man with one watch knows what time it is; a man with two watches is
never sure. - Lee Segall
--
http://mail.python.org/mailman/listinfo/python-list


Re: nohup and os.system

2009-03-11 Thread Cameron Simpson
On 11Mar2009 21:05, Gideon  wrote:
| I've got a python script, batch.py that, amongst other things,
| executes commands:
| 
| os.system('cmd1')
| os.system('cmd2')
| 
| now, these programs output certain information at the command line,
| and if i execute
| 
| ./batch.py
| 
| it shows up as I would expect.
| 
| However, if i run
| 
| nohup ./batch.py &
| 
| then while everything runs, but the intermediate output that generated
| by each os.system call does not get appended to nohup.out until
| *after* the command finishes executing.  Is there a way I can get this
| data to be appended in real time?
| 
| What I'm doing in practice is sticking a lightweight python script
| around an existing fortran binary, and I'd like to be able to monitor
| the progress of the binary be checking the nohup.out log.

You're being bitten by a standard bit of stdio-on-UNIX. With the stdio
library, stdout behaves differently (by default) if attached to a
terminal. If stdout is attached to a terminal it is line buffered,
and output is flushed on newlines. Otherwise it is block buffered
and flushed when the buffer fills (8192 bytes or some number like that,
depending on the system).

This is for efficiency: with block buffering, when you call the stdio
fwrite() function is merely copies data into a buffer, and does not call an
OS write() call unless the buffer is full. This results in fewer OS calls,
fewer data copies, fewer context switches and thus higher throughput.

Programs usually line buffer to a terminal because that produces more
timely output for people such as yourself when watching it.

This buffering is happening inside the cmd1 and cmd2 programs, not in
your python script. (Python will buffer like this too, but that's not
your problem here.)

With nohup, the outputs of cmd1 and cmd2 are going to the nohup.out
file, and thus are set to block buffering. Unless cmd1 and cmd2 have
special command line switches to get them to line buffer (or no-buffer)
your only recourse is to attach them to terminals, thus tricking them
into doing line buffering again. Fortunately, this is made convenient by
the script command. For example, try changing the string "cmd1" into the
string:

  script -a -q -f nohup.out cmd1

(You will probably need GNU script for the -f option; see "man script"
for details, or just try it.)

The other thing to be aware of when doing this is that script logs the
output post the terminal character driver; this will normally translate
newlines in the program output into carriage-return and then newline
because that is what a terminal requires to move the cursor as needed.

Cheers,
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

Network Planning Constraint Of The Month:
You can't send bits over a non-existant link.
- Valdis Kletnieks 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question on periods in strings

2009-03-11 Thread John Yeung
On Mar 11, 9:42 pm, "Philip Bloom"  wrote:
> #test A
> #runs in 5.8 seconds.
> from datetime import datetime
> testvar2='9a00'
> startTime = datetime.now()
> filehandle=open('testwriting.txt','w')
> for var in range(1000):
>     filehandle.write(testvar2)
> filehandle.close()
> print (datetime.now() - startTime)
>
> #test B
> #runs in 10.9 seconds.
> from datetime import datetime
> testvar2='9.00'
> startTime = datetime.now()
> filehandle=open('testwriting.txt','w')
> for var in range(1000):
>     filehandle.write(testvar2)
> filehandle.close()
> print (datetime.now() - startTime)

Your results are fascinating and utterly bizarre.  I cannot reproduce
them.  I copied and pasted your code and ran as a single program on
Python 2.6.1 on my WinXP machine.  After several trials, the first
print always showed about 4.8 seconds and the second always about 4.6
seconds.  Transposing test A and B resulted in the first print (now
test B) showing 4.8 and the second print 4.6.

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


Re: A Dangling Tk Entry

2009-03-11 Thread W. eWatson
I happened to notice that BJ and Rhondi started a small subthread to this, 
so I thought I'd explore it. It led to interesting things, but not for its 
content. I reviewed some things. I'll do you the courtesy or wrapping this up.


I'll get straight to the point and be a minimal as possible in my response, 
without accusing or implying anyone of anything.


My guess is that the first culprit was here:
   entry = Entry(master, width=10, ...
   entry.insert(0,self.slowdown)   <--- no affect.
The next culprit was this:
   self.anumberVar.set( "%d" % self.sdict["anumber"] )
One must be very careful of what is in "anumber".

That's it. Nothing else.

The changes I've made in the 2000 lines of code work, as I had intended. The 
sample code now works as I had intended. (And no, I am not providing it. 
This thread doesn't need more explanation.) I can now proceed to eliminate 
all the control variables.


You'll have to be satisfied with what I've said. I have no more to say. All 
parts of this thread I consider closed.


"Include me out." -- Yogi Berra




--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 

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


Re: ipython / vs \ in readline on MS Windows (and ipython help grepper)

2009-03-11 Thread Tim Roberts
bdb112  wrote:
>
>Q1/ I run a standard python ditribution with ipython and readline
>under cygwin.  The tab filename completion works fine in the OS (bash
>shell) as expected, and tab filename completion at the ipython command
>line works, but with MS style path separators (backslash: run examples
>\test.py) which the run command itself interprets unix style
>ERROR: File `examplestest.py` not found.

You have full source of ipython.  You should be able to find where it does
filename completion and change the separator character.  It probably uses
os.path.join -- you'll have to change it to something like '/'.join.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


nohup and os.system

2009-03-11 Thread Gideon
I've got a python script, batch.py that, amongst other things,
executes commands:

os.system('cmd1')
os.system('cmd2')

now, these programs output certain information at the command line,
and if i execute

./batch.py

it shows up as I would expect.

However, if i run

nohup ./batch.py &

then while everything runs, but the intermediate output that generated
by each os.system call does not get appended to nohup.out until
*after* the command finishes executing.  Is there a way I can get this
data to be appended in real time?

What I'm doing in practice is sticking a lightweight python script
around an existing fortran binary, and I'd like to be able to monitor
the progress of the binary be checking the nohup.out log.
--
http://mail.python.org/mailman/listinfo/python-list


Re: What happened to NASA at Python? :(

2009-03-11 Thread Mensanator
On Mar 11, 9:55�pm, Benjamin Peterson  wrote:
> r  gmail.com> writes:
>
>
>
> > The Python home page no longer sports a promotion from NASA. What
> > happened, did we lose NASA. Where did they go?
>
> The python.org guys just decided it would be nice to have some
> different graphics.

If they were so keen on new graphics, why did 2.6 revert
to the same icons that 2.4 used? (At least they did on my
machine. After installing 2.6, I no longer had the new
2.5 icons but had reverted to the earlier ones.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: What happened to NASA at Python? :(

2009-03-11 Thread r
On Mar 11, 10:09 pm, s...@pobox.com wrote:
> In fact, graphics were added for several organizations.  I believe they will
> be chosen randomly.  NASA is still there.
>
> --http://mail.python.org/mailman/listinfo/python-list

Whew! Thats good news, i thought we had lost their support.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Minimilistic Python on Linux?

2009-03-11 Thread Gabriel Genellina
En Thu, 12 Mar 2009 00:41:18 -0200, Royce Wilson   
escribió:

On Wed, Mar 11, 2009 at 9:33 PM, Royce Wilson  wrote:


Thanks for the quick responses. When I view sys.modules I get this:

 sre_compile _collections locale _sre functools encodings site operator  
io
__main__ copyreg _weakref abc builtins encodings.cp437 errno  
sre_constants

re encodings.latin_1 collections ntpath nt genericpath stat zipimport
_codecs encodings.utf_8 encodings.cp1252 sys codecs _bytesio _thread  
os.path
_functools _locale keyword signal _stringio _weakrefset  
encodings.aliases

sre_parse os _abcoll _fileio

Each module is seperated by a space.

Can you give me in instructions on how to remove the site.py  
dependencies?


Start python with the -S option

--
Gabriel Genellina

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


Re: What happened to NASA at Python? :(

2009-03-11 Thread skip

>> The Python home page no longer sports a promotion from NASA. What
>> happened, did we lose NASA. Where did they go?

> The python.org guys just decided it would be nice to have some
> different graphics.

In fact, graphics were added for several organizations.  I believe they will
be chosen randomly.  NASA is still there.

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


Re: What happened to NASA at Python? :(

2009-03-11 Thread Benjamin Peterson
r  gmail.com> writes:

> 
> The Python home page no longer sports a promotion from NASA. What
> happened, did we lose NASA. Where did they go?

The python.org guys just decided it would be nice to have some
different graphics.



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


What happened to NASA at Python? :(

2009-03-11 Thread r
The Python home page no longer sports a promotion from NASA. What
happened, did we lose NASA. Where did they go?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Minimilistic Python on Linux?

2009-03-11 Thread Royce Wilson
On Wed, Mar 11, 2009 at 9:33 PM, Royce Wilson  wrote:

> Thanks for the quick responses. When I view sys.modules I get this:
>
>  sre_compile _collections locale _sre functools encodings site operator io
> __main__ copyreg _weakref abc builtins encodings.cp437 errno sre_constants
> re encodings.latin_1 collections ntpath nt genericpath stat zipimport
> _codecs encodings.utf_8 encodings.cp1252 sys codecs _bytesio _thread os.path
> _functools _locale keyword signal _stringio _weakrefset encodings.aliases
> sre_parse os _abcoll _fileio
>
> Each module is seperated by a space.
>
> Can you give me in instructions on how to remove the site.py dependencies?
> BTW I'm using Python 3.0 as the point is to "modernize" linux.
>
>   On Wed, Mar 11, 2009 at 9:02 PM, Gabriel Genellina <
> gagsl-...@yahoo.com.ar> wrote:
>
>> En Wed, 11 Mar 2009 23:09:51 -0200, Royce Wilson 
>> escribió:
>>
>>
>> I'm working on a minimilistic linux project and would like to include
>>> Python. However, since Python is around 17MB (compressed) and previous
>>> releases of this linux distro are under 100MB (compressed)  standard
>>> Python
>>> releases are much to large. I just need the runtime libs of Python, the
>>> absoulute bare necesties. I do not need any kind of GUI. Also, with the
>>> standard library, I would like to remove all the files execpt the
>>> ones Python needs to run and only add new ones as required.
>>>
>>
>> I think Python doesn't *require* any external module to be able to start.
>> "site.py" is searched, but may be missing. Probably the interpreter
>> executable alone is enough (but I've never tested it!). Anyway, most Python
>> users would expect all the standard modules to be available, though... part
>> of the usefulness of the language comes from its "batteries included".
>>
>> As a test, you might start with a clean install, then invoke the
>> interpreter and look at sys.modules. The modules you find there (those that
>> are not built-in) would be the minimum you need to run Python. On Windows I
>> got this (this was not a true "clean" install, I just disabled
>> sitecustomize.py and unset my PYTHONSTARTUP variable): UserDict _abcoll abc
>> codecs copy_reg encodings functools genericpath linecache locale ntpath os
>> re site sre_compile sre_constants sre_parse stat types warnings.
>> Most of these are dependencies from "site.py"; if you omit it, the list is
>> even shorter (just "codecs" and the "encodings" package; note that some
>> modules are built-in in Windows but external on Linux).
>> So it looks that -apart from those few modules- you may include as much or
>> as few of the standard library as you want, but consider what your users
>> would expect to be available...
>>
>> --
>> Gabriel Genellina
>>
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Minimilistic Python on Linux?

2009-03-11 Thread Gabriel Genellina
En Wed, 11 Mar 2009 23:09:51 -0200, Royce Wilson   
escribió:



I'm working on a minimilistic linux project and would like to include
Python. However, since Python is around 17MB (compressed) and previous
releases of this linux distro are under 100MB (compressed)  standard  
Python

releases are much to large. I just need the runtime libs of Python, the
absoulute bare necesties. I do not need any kind of GUI. Also, with the
standard library, I would like to remove all the files execpt the
ones Python needs to run and only add new ones as required.


I think Python doesn't *require* any external module to be able to start.  
"site.py" is searched, but may be missing. Probably the interpreter  
executable alone is enough (but I've never tested it!). Anyway, most  
Python users would expect all the standard modules to be available,  
though... part of the usefulness of the language comes from its "batteries  
included".


As a test, you might start with a clean install, then invoke the  
interpreter and look at sys.modules. The modules you find there (those  
that are not built-in) would be the minimum you need to run Python. On  
Windows I got this (this was not a true "clean" install, I just disabled  
sitecustomize.py and unset my PYTHONSTARTUP variable): UserDict _abcoll  
abc codecs copy_reg encodings functools genericpath linecache locale  
ntpath os re site sre_compile sre_constants sre_parse stat types warnings.
Most of these are dependencies from "site.py"; if you omit it, the list is  
even shorter (just "codecs" and the "encodings" package; note that some  
modules are built-in in Windows but external on Linux).
So it looks that -apart from those few modules- you may include as much or  
as few of the standard library as you want, but consider what your users  
would expect to be available...


--
Gabriel Genellina

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


Re: Can python (CPython) and IPython coexist normally on the same computer ?

2009-03-11 Thread John Machin
On Mar 12, 11:57 am, scoop  wrote:
> On Wed, 11 Mar 2009 17:20:09 -0700 (PDT), John Machin
>
>
>
>  wrote:
> >Do you mean this IPython:
> >http://en.wikipedia.org/wiki/IPython
> >or do you mean Iron Python:
> >http://en.wikipedia.org/wiki/IronPython
>
> >IPython is a front-end for the CPython interpretor, as is IDLE, etc.
> >"differences", "switch to" and "supports standard libraries" are
> >rather meaningless questions.
>
> >Iron Python is an alternative implementation of a Python interpreter,
> >whose target is the .NET/Mono platform. It supports standard libraries
> >written in Python. I believe there is a project called Ironclad whose
> >aim is to be able to use libraries written in C/C++ (like numpy) but
> >this is not available yet.
>
> Oh, sorry. I didn't know Ipython existed, so I (rather foolishly)
> abbreviated Iron Python into IPython.
> So generally, yes, my questions were aimed at Iron python. So what
> you're saying is there are still some complications about using numpy
> and matplotlib in Iron ?

It seems that your googler is broken. While you are waiting for
someone to fix it for you, browse this:
http://ironpython.codeplex.com/Wiki/View.aspx?title=FAQ&referringTitle=Home
and search the rather long page for "Numpy" (without the quotes).

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


Re: Minimilistic Python on Linux?

2009-03-11 Thread Christian Heimes
Royce Wilson schrieb:
> I'm working on a minimilistic linux project and would like to include
> Python. However, since Python is around 17MB (compressed) and previous
> releases of this linux distro are under 100MB (compressed)  standard Python
> releases are much to large. I just need the runtime libs of Python, the
> absoulute bare necesties. I do not need any kind of GUI. Also, with the
> standard library, I would like to remove all the files execpt the
> ones Python needs to run and only add new ones as required.
> 
> What can I strip off Python? Thanks.

I start by stripping off all documentation in Docs/, the Lib/test
directory with unit tests, the Tools/ directory with optional stuff and
all Windows related code in PC/, PCBuild and PCBuild8. Optional
components like bsddb, tk and curses take up some space, too. Last but
not least you can put all .py and .pyc files in a zip file. The file
must be called "/usr/local/lib/python25.zip" if sys.prefix is equal to
"/usr/local".

Christian

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


RE: Question on periods in strings

2009-03-11 Thread Philip Bloom
Thanks for the welcome :)

You're right.  Here's with the missed line (I was cutting out commented parts). 
 Hopefully these are all cut/paste-able.

#test A
#runs in 5.8 seconds.
from datetime import datetime
testvar2='9a00'
startTime = datetime.now()
filehandle=open('testwriting.txt','w')
for var in range(1000):
filehandle.write(testvar2)
filehandle.close()
print (datetime.now() - startTime)


#test B
#runs in 10.9 seconds.
from datetime import datetime
testvar2='9.00'
startTime = datetime.now()
filehandle=open('testwriting.txt','w')
for var in range(1000):
filehandle.write(testvar2)
filehandle.close()
print (datetime.now() - startTime)

I do use the same filename, but I've run the tests in different orders and it's 
made no difference.  Repeatedly running the same test results in the same 
numbers with only minor fluctuations (as would be expected from cache issues).  
Ten runs in a row of Test B all result in about 11 seconds each.  Ten runs in a 
row of Test A all result in about 6 seconds each.

The range is not actually a meaningful adjustment as the time results are 
identical switching out xrange (as I believe they should be since in 2.6 range 
maps to xrange for the most part according to some of the docs).  

#Test C
#runs in 8.9 seconds.
from datetime import datetime
testvar2='9.00'
startTime = datetime.now()
join=[]
filehandle=open('testwriting.txt','w')
for var in range(1000):
join.append(testvar2)
"".join(join)
print (datetime.now() - startTime) #3.01 seconds   
filehandle.write("".join(join))
filehandle.close()
print (datetime.now() - startTime) #8.9 seconds.

#Test D
#runs in 3.8 seconds.
from datetime import datetime
testvar2='9a00'
startTime = datetime.now()
join=[]
filehandle=open('testwriting.txt','w')
for var in range(1000):
join.append(testvar2)
"".join(join)
print (datetime.now() - startTime) #3.09 seconds   
filehandle.write("".join(join))
filehandle.close()
print (datetime.now() - startTime) #3.87 seconds.

This is a variation that shows it more noticeably.  I do an extra join to 
demonstrate that's not taking the time.  Effectively nothing is really 
different it seems like other than the period.  It's all intentionally small 
python code since it originated from just seeing what some variations on file 
writes might differ in scaling.
 
-Original Message-
From: python-list-bounces+pbloom=crystald@python.org 
[mailto:python-list-bounces+pbloom=crystald@python.org] On Behalf Of 
Gabriel Genellina
Sent: Wednesday, March 11, 2009 6:17 PM
To: python-list@python.org
Subject: Re: Question on periods in strings

En Wed, 11 Mar 2009 22:35:22 -0200, Philip Bloom   
escribió:

> Hello, this is my first time posting to the list, but my curiosity here
> is great.

Welcome!

> I was randomly toying with file writes and I ran into something that
> seemed quite odd to me.  When a period is in a string, file write takes
> about double the time.  I saw similar things with newlines, but I
> figured that was because it was doing a lookup on the escape-d n.  All
> other symbols seem to not have this problem, so I'm curious what's
> special about periods that they take so much longer to write to file.

I doubt the period is actually the culprit. There are lots of other  
variables - like disk and memory fragmentation, cpu load, ...
You omitted part of your code: do you use the same filename on both tests?  
(Note that starting with an empty file is not the same as using a  
preallocated file).
Also, do you always run both scripts in the same order? (maybe "the  
second" always runs faster, no matter which one is it).
Also note that you're measuring the time to allocate a list containing ten  
million integer objects (the range() call). xrange is a less perturbing  
option.

-- 
Gabriel Genellina

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

__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
__

__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
__
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question on periods in strings

2009-03-11 Thread Gabriel Genellina
En Wed, 11 Mar 2009 22:35:22 -0200, Philip Bloom   
escribió:



Hello, this is my first time posting to the list, but my curiosity here
is great.


Welcome!


I was randomly toying with file writes and I ran into something that
seemed quite odd to me.  When a period is in a string, file write takes
about double the time.  I saw similar things with newlines, but I
figured that was because it was doing a lookup on the escape-d n.  All
other symbols seem to not have this problem, so I'm curious what's
special about periods that they take so much longer to write to file.


I doubt the period is actually the culprit. There are lots of other  
variables - like disk and memory fragmentation, cpu load, ...
You omitted part of your code: do you use the same filename on both tests?  
(Note that starting with an empty file is not the same as using a  
preallocated file).
Also, do you always run both scripts in the same order? (maybe "the  
second" always runs faster, no matter which one is it).
Also note that you're measuring the time to allocate a list containing ten  
million integer objects (the range() call). xrange is a less perturbing  
option.


--
Gabriel Genellina

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


Minimilistic Python on Linux?

2009-03-11 Thread Royce Wilson
I'm working on a minimilistic linux project and would like to include
Python. However, since Python is around 17MB (compressed) and previous
releases of this linux distro are under 100MB (compressed)  standard Python
releases are much to large. I just need the runtime libs of Python, the
absoulute bare necesties. I do not need any kind of GUI. Also, with the
standard library, I would like to remove all the files execpt the
ones Python needs to run and only add new ones as required.

What can I strip off Python? Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can python (CPython) and IPython coexist normally on the same computer ?

2009-03-11 Thread scoop
On Wed, 11 Mar 2009 17:20:09 -0700 (PDT), John Machin
 wrote:


>Do you mean this IPython:
>http://en.wikipedia.org/wiki/IPython
>or do you mean Iron Python:
>http://en.wikipedia.org/wiki/IronPython
>
>IPython is a front-end for the CPython interpretor, as is IDLE, etc.
>"differences", "switch to" and "supports standard libraries" are
>rather meaningless questions.
>
>Iron Python is an alternative implementation of a Python interpreter,
>whose target is the .NET/Mono platform. It supports standard libraries
>written in Python. I believe there is a project called Ironclad whose
>aim is to be able to use libraries written in C/C++ (like numpy) but
>this is not available yet.
>

Oh, sorry. I didn't know Ipython existed, so I (rather foolishly)
abbreviated Iron Python into IPython.
So generally, yes, my questions were aimed at Iron python. So what
you're saying is there are still some complications about using numpy
and matplotlib in Iron ?

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


Re: Strange array.array performance

2009-03-11 Thread Aahz
In article ,
Maxim Khitrov   wrote:
>
>Interesting, though I'm not able to replicate that last outcome. The
>string method is still the fastest on my machine. Furthermore, it
>looks like the order in which you do the multiplication also matters -
>(8 * size * '\0') is faster than ('\0' * 8 * size). 

That's not surprising -- the latter does two string multiplication
operations, which I would expect to be slower than int multiplication.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"All problems in computer science can be solved by another level of 
indirection."  --Butler Lampson
--
http://mail.python.org/mailman/listinfo/python-list


Question on periods in strings

2009-03-11 Thread Philip Bloom
Hello, this is my first time posting to the list, but my curiosity here
is great.

I was randomly toying with file writes and I ran into something that
seemed quite odd to me.  When a period is in a string, file write takes
about double the time.  I saw similar things with newlines, but I
figured that was because it was doing a lookup on the escape-d n.  All
other symbols seem to not have this problem, so I'm curious what's
special about periods that they take so much longer to write to file.

#Done in python 2.6.1
#runs in 5.8 seconds.

from datetime import datetime

testvar2='9a00'

startTime = datetime.now()

for var in range(1000):

filehandle.write(testvar2)

filehandle.close()

print (datetime.now() - startTime)

 

 

#runs in 10.9 seconds.

from datetime import datetime

testvar2='9.00'

startTime = datetime.now()

for var in range(1000):

filehandle.write(testvar2)

filehandle.close()

print (datetime.now() - startTime)

Thank you to any who answer for assuaging my curiosity.


__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
__--
http://mail.python.org/mailman/listinfo/python-list


Re: factory functions & methods

2009-03-11 Thread Aaron Brady
On Mar 11, 12:52 pm, Piet van Oostrum  wrote:
> > Aaron Brady  (AB) wrote:
> >AB> Hello,
> >AB> I am creating a container.  I have some types which are built to be
> >AB> members of the container.  The members need to know which container
> >AB> they are in, as they call methods on it, such as finding other
> >AB> members.  I want help with the syntax to create the members.
> >AB> Currently, the container has to be a parameter to the instantiation
> >AB> methods.  I want the option to create members with attribute syntax
> >AB> instead.
> >AB> Currently, I have:
> >AB> cA= Container( )
> >AB> obA= SomeType( cA )
> >AB> obB= OtherType( cA, otherarg )
> >AB> I want:
> >AB> cA= Container( )
> >AB> obA= cA.SomeType( )
> >AB> obB= cA.OtherType( otherarg )
> >AB> What are my options?
> >AB> P.S.  The container and members are C extension types, not pure Python.
>
> You could do something like this (translated to C)
>
> class Container(object):
>   def __init__(self):
>     self.items = []
>   def add(self, item):
>     self.items.append(item)
>   def SomeType(self):
>       newobj = SomeType()
>       self.add(newobj)
>   def OtherType(self, arg):
>       newobj = OtherType(arg)
>       self.add(newobj)
>
> class SomeType(object):
>   def __init__(self):
>       pass
>
> class OtherType(SomeType):
>   def __init__(self, arg):
>     SomeType.__init__(self)
>     self.x = arg
>
> cA = Container()
> obA = cA.SomeType()
> obB = cA.OtherType(5)
> print cA.items
>
> --
> Piet van Oostrum 
> URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4]
> Private email: p...@vanoostrum.org

I like it.  It's a combination of andrew's suggestion, and what I've
been considering.  What I did was (approximately):

class Container:
def __init__( self ):
self.SomeType= type( 'BoundSomeType', (SomeType,),
{ '__new__': custom_new } )
self.OtherType= type( 'BoundOtherType', (OtherType,),
{ '__new__': custom_new } )

cA = Container()
obA = cA.SomeType()
obB = cA.OtherType(5)

It has the advantage that 'cA.SomeType' is a subclass of SomeType;
specifically, that it responds in kind to SomeType.  It's a bit
heavyweight on the consumption of resources.  'custom_new' actually
returns an instance of the base.

I am looking for ways to allow user-defined subclasses.

class CustomType( cA.MemberBase ):
...

obC= CustomType( ) #unusable in other instances

-or-

class CustomType( MemberBase ):
...

obC= cA.CustomType( ) #explicit member or dynamic (Gabriel)?
#of base (Piet) or instance (andrew)?

-or-

class CustomType( MemberBase ):
...

obC= CustomType( ) #disallow "as attribute" creation

Or, some combination of -2- and -1- or -3-.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can python (CPython) and IPython coexist normally on the same computer ?

2009-03-11 Thread John Machin
On Mar 12, 10:17 am, scoop  wrote:
> I know I could just try to install it and see, but I've got my
> configuration just right, so I don't want to mess it up (maybe) with
> IPython.
>
> Also, can someone please point me to some page where I can find
> differences between C and I Python. I'm learning Python using
> "Learning python" (figures :), so I was wondering - what are the
> practical differences between the two ? If I start with IPython, will
> I be able to switch to CPython later, or will I have trouble with that
> ? Does IPython supports standard libraries like numpy and matplotlib ?
>

Do you mean this IPython:
http://en.wikipedia.org/wiki/IPython
or do you mean Iron Python:
http://en.wikipedia.org/wiki/IronPython

IPython is a front-end for the CPython interpretor, as is IDLE, etc.
"differences", "switch to" and "supports standard libraries" are
rather meaningless questions.

Iron Python is an alternative implementation of a Python interpreter,
whose target is the .NET/Mono platform. It supports standard libraries
written in Python. I believe there is a project called Ironclad whose
aim is to be able to use libraries written in C/C++ (like numpy) but
this is not available yet.

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


Re: Can python (CPython) and IPython coexist normally on the same computer ?

2009-03-11 Thread Chris Rebert
On Wed, Mar 11, 2009 at 4:17 PM, scoop  wrote:
> I know I could just try to install it and see, but I've got my
> configuration just right, so I don't want to mess it up (maybe) with
> IPython.
>
> Also, can someone please point me to some page where I can find
> differences between C and I Python. I'm learning Python using
> "Learning python" (figures :), so I was wondering - what are the
> practical differences between the two ? If I start with IPython, will
> I be able to switch to CPython later, or will I have trouble with that
> ? Does IPython supports standard libraries like numpy and matplotlib ?

ipython is just an improved Python shell (interactive
interpreter/REPL), not an alternate Python implementation. As far as I
know, it is based on CPython and normally requires CPython to operate.

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Behaviour of os.rename()

2009-03-11 Thread Rhodri James
On Wed, 11 Mar 2009 14:35:01 -, venutaurus...@gmail.com  
 wrote:



On Mar 11, 7:20 pm, Tim Golden  wrote:

venutaurus...@gmail.com wrote:
> Hello all,
>             I got a suspicion on the behaviour of os.rename
> (src,dst).If the src is the path of a file and dst is a new filename
> this os.rename() function is infact creating a new file with the dst
> name in the current working directory and leaving the src as it is. Is
> this the expected behavior?


Yes, though part of this is Windows being bloody-minded.  It is always the  
case that if you don't give a rooted pathname (one starting with r"\") to  
pretty much any built-in function expecting a filename (in pretty much any  
language, come to that), the pathname will be assumed to be relative to  
the current working directory.  Windows complicates this by having a  
current drive too, and per-drive working directories to go with them, so  
"file.txt", "D:file.txt", r"\path\to\file.txt" and r"D:\path\to\file.txt"  
could well all be different files in different places.



> If i want the actual source file in its
> orignal location to be renamed without doing os.chdir() to that
> directory, is that possible?


Yes.  Give the full pathname, with drive letters and everything.


os.rename on windows calls the Windows MoveFile API:

 http://msdn.microsoft.com/en-us/library/aa365239(VS.85).aspx

Have a look at the details on that page to see what
the limitations / actions are. But remember -- as I've
indicated elsewhere -- to use the ur"\\?\c:\..." form
of the file names.

And let us know if that works :)


That actually was an illustration. As you've told in another chain, it
isn't working even after appending "\\?\"


Tim's point was that you should read the MS documentation.  To be fair it  
doesn't mention doing a copy and (failing to) delete instead of moving the  
file when doing cross-volume renames, but that's what the OS will have to  
do.


--
Rhodri James *-* Wildebeeste Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Can python (CPython) and IPython coexist normally on the same computer ?

2009-03-11 Thread scoop
I know I could just try to install it and see, but I've got my
configuration just right, so I don't want to mess it up (maybe) with
IPython.

Also, can someone please point me to some page where I can find
differences between C and I Python. I'm learning Python using
"Learning python" (figures :), so I was wondering - what are the
practical differences between the two ? If I start with IPython, will
I be able to switch to CPython later, or will I have trouble with that
? Does IPython supports standard libraries like numpy and matplotlib ?

Greetings to all of you who actually read all of this, and got this
far :)
Hope all is well,
   Scoop
--
http://mail.python.org/mailman/listinfo/python-list


Re: An error in threading.py?

2009-03-11 Thread Falcolas
On Mar 11, 4:15 pm, Oltmans  wrote:
> Hi, all. I'm trying to use Mechanize in a multithreaded program--
> purpose of which is to fill out a form on a website using concurrent
> threads. Guys, trust me I've spent a lot of time to figure out the
> problem but I'm completed puzzled. Firstly, I've listed the errors and
> then the program listing (with imports omitted)
>
> Error:
>
> Traceback (most recent call last):
>   File "C:\Python25\lib\threading.py", line 460, in __bootstrap
>     self.run()
>   File "tmechanize.py", line 21, in run
>     with lock:
> NameError: global name 'lock' is not defined

Time for the obvious question - where do you define "lock"? If you're
trying to put a mutex around your increment, you need a lock pre-
defined to use it. So, you'll need to add something like "lock = Lock
()" near the top, with a "global lock" before you try using it in your
with statement.

If you try using Lock() directly in the thread, you'll create a new
lock per thread, thus defeating the purpose of trying to lock in the
first place.

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


Re: An error in threading.py?

2009-03-11 Thread Robert Kern

On 2009-03-11 17:15, Oltmans wrote:

Hi, all. I'm trying to use Mechanize in a multithreaded program--
purpose of which is to fill out a form on a website using concurrent
threads. Guys, trust me I've spent a lot of time to figure out the
problem but I'm completed puzzled. Firstly, I've listed the errors and
then the program listing (with imports omitted)


Why omit the imports?


Error:

Traceback (most recent call last):
   File "C:\Python25\lib\threading.py", line 460, in __bootstrap
 self.run()
   File "tmechanize.py", line 21, in run
 with lock:
NameError: global name 'lock' is not defined


The problem is in tmechanize.py, not threading.py. You forgot to actually make 
the lock object.


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


An error in threading.py?

2009-03-11 Thread Oltmans
Hi, all. I'm trying to use Mechanize in a multithreaded program--
purpose of which is to fill out a form on a website using concurrent
threads. Guys, trust me I've spent a lot of time to figure out the
problem but I'm completed puzzled. Firstly, I've listed the errors and
then the program listing (with imports omitted)

Error:

Traceback (most recent call last):
  File "C:\Python25\lib\threading.py", line 460, in __bootstrap
self.run()
  File "tmechanize.py", line 21, in run
with lock:
NameError: global name 'lock' is not defined


Program:
-
#!/usr/bin/env python
requestNumber=0
class Requests(Thread):

def __init__(self, times):
Thread.__init__(self)
self.times=times

self.html=' '
self.requestTime={}
self.starttime=0
self.endtime=0
self.br= Browser()
def run(self):


for i in range(0,self.times):
self.starttime=time.clock()
self.SendRequest()
self.endtime=time.clock()
with lock:
global requestNumber
requestNumber += 1
print 'locking the time'
self.requestTime[requestNumber]=self.endtime -
self.starttime


def SendRequest(self): #A class method
# it sends a request to website using mechanize library
self.br.add_password("https://example.com/admin";, "admin",
"admin")
res=self.br.open("https://example.com/admin";)
print 'Successfully loggedin '
self.html=res.read()

print 'Filling in the form'
self.br.select_form(name="formOne")
self.br["textbox"]="www.google.com"
self.br["textBox1"]='www.example.com'
self.br["users[0].firstName"]="firstName"
self.br["users[0].lastName"]="LastName"
self.br["users[0].emailAddress"]="fn...@example.com"
print 'Submitting the form'
resp=self.br.submit()
self.html=resp.read()

def startThis(times,reqs):
#print 'Threads ='+str(times)
#print 'Reques/Thread ='+ str(maxReqs)

threads=[]
for i in range (0,reqs):
owner=Requests(times)
owner.start()
threads.append(owner)

for thread in threads:
thread.join()

if __name__=="__main__":
#I want to create 2 threads, each of them will execute twice. At
least that is the intention.
startThis(2,2)


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


Re: Stopping SocketServer on Python 2.5

2009-03-11 Thread Falcolas
On Mar 11, 1:11 pm, David George  wrote:
> Again, problem here is the issue of being unable to kill the server
> while it's waiting on a request. In theory, i could force it to
> continue by sending some sort of junk data with the method i use to
> stop the server, but that seems a bit hacky, don't you think?

Dave,

I agree, it does.

I'm in a bit over my head at this point, but does setting
self.socket.settimeout(0.5) cause the call to get_request (and thus
self.socket.accept()) to timeout? If so, that may be your ticket,
since socket.error exceptions are already caught by the TCPServer
class.

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


[ANN] Pyjamas 0.5 Web Widget Set and python-to-javascript Compiler released

2009-03-11 Thread Luke Kenneth Casson Leighton
This is the release of Pyjamas 0.5, a python-to-javascript
compiler with an AJAX Web Widget set, for creating python
desktop-like applications that run in all major web browsers.

http://pyjs.org

Pyjamas is NOT "another AJAX framework" where the
widgets are predefined, fixed and inflexible.  Thanks to
the compiler, Pyjamas is a dynamic "framework's framework"
where developers can define their own web framework, in
Python classes and modules instead of being forced to
write code in pure Javascript.

The Pyjamas Web Widget set makes it possible for users
to develop Rich Media Applications as if they were writing
desktop applications, without having to know any Javascript,
or even very much HTML.  Developing applications using
Pyjamas is much more similar to and has far more in
common with developing PyQT4 or PyGtk2 applications than
it has with "traditional" AJAX web development.  Yet,
thanks to the applications actually running in a Web
Browser, developers get the best of both worlds.

For those people who prefer to stick to "true" Desktop
development, or who prefer to debug applications in
Python rather than rely on the debugging features of
Web Browser engines, there is the sister project,
Pyjamas-Desktop - http://pyjd.org

Pyjamas-Desktop allows the same application source code
to be run, unmodified, in both the web browser and as
a desktop application.

The 0.5 release is a significant functionality update.

Additions have been made to the core python-to-javascript
compiler such as support for exceptions (try / except), lambda,
and a debug option to track and print run-time stack traces,
in cases where the deployment of a javascript script debugger
is difficult or impossible (IE6 running under Wine).

Also, the code-generator has undergone a reorganisation,
and now has much better support for local and global
variable, function, class and module scopes.

Support for Dynamic loading of modules has been added,
where each python module now has its own javascript
(compiled) "cache" file.  This makes it possible to
share the modules across the 5 supported platforms,
bringing a dramatic reduction in the amount of compiled
javascript that is deployed.  Also, support for dynamic
module loading makes it much clearer how developers may
interact with pyjamas-compiled modules from existing
applications which already have an AJAX framework in place.

Users of previous versions of Pyjamas should note that the
UI widget classes have undergone a restructuring, reducing
the 4,000 line ui.py into 70 separate small modules.  The
reorganisation allows applications to undergo a significant
reduction in the amount of compiled javascript, by only
importing UI Modules that are needed.  Reorganisation
scripts can be found in contrib/pyjamas_0.4_0.5_upgrade/
that will help in the conversion of existing applications.

Also, to make developers' lives easier in both the testing
and deployment of pyjamas applications, buildout has been
added, along with a standard setup.py.

Finally, an experiment is included, which is the beginnings
of a way to speed up the execution of standard python,
in a similar way to Python-Psyco.

The combination of the pyjs python-to-javascript compiler
and PyV8 - http://code.google.com/p/pyv8 - becomes a JIT
compiler that supports both ARM and i386 assembler.

The use of the Google V8 JIT compiler provides a means
to dynamically load standard c-based python modules,
and the use of pyjs means that the intermediate javascript
is actually still human-readable.  These are two distinct
advantage over pypy, and the third advantage is that the
direct translation, instead of going through an intermediary
(RPython) means that the full dynamic semantics of the
python language are reflected into javascript, and still available.

Downloads are available at:
   http://code.google.com/p/pyjamas/downloads/list
   https://sourceforge.net/project/platformdownload.php?group_id=239074
   http://pypi.python.org/pypi/Pyjamas/0.5

Pyjamas Book is at:
   http://pyjs.org/book/output/Bookreader.html#Getting%20Started

Links to other documentation is on the main site:
   http://pyjs.org

Development and discussion is at:
   http://groups.google.com/group/pyjamas-dev

Subversion Source repository is at:
   https://sourceforge.net/scm/?type=svn&group_id=239074

IRC Channel is:
   #pyjamas at irc.freenode.net
IRC Logs (thanks to Tim Riker) at:
   http://ibot.rikers.org/%23pyjamas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why is lambda allowed as a key in a dict?

2009-03-11 Thread r
On Mar 11, 4:32 pm, Terry Reedy  wrote:
> Similarly, if one is populating a LARGE structure with duplicate values,
> it may be worthwhile to cache values that are not cached by the interpreter.

Thanks Terry,
Actually i had no idea how Python handled strings(immutables)
internally but after considering this for 1 second it makes complete
sense. I have never compared two "like" strings to see what the
outcome will be because i never needed to. Just like i never used a
lambda as a dict key and probably never will. But these things are
good to know.

When i learn something new (like Python) i tend to jump right in and
learn by trial and error -- sometimes it feels more like trial by fire
-- that is how i have learned the Python language. I still have not
read Guido's tutorial from front to back (not proud of that BTW),
actually i haven't read but maybe 10% of it!

I think now would be a good time to read the entire tut from my
"field" experienced level and fill in all the (maybe mostly
insignificant (but very important)) details of how python handles data
internally. This should give me a much better insight of the language
and will most defiantly improve my code writing skills.

Sorry Graig for my misinterpretation of your post. And thanks Terry
for the great explanation.


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


Re: Why is lambda allowed as a key in a dict?

2009-03-11 Thread Terry Reedy

r wrote:

On Mar 11, 3:40 pm, Craig Allen  wrote:

On Mar 10, 1:39 pm, Paul Rubin  wrote:



Identical strings don't necessarily have the same id:


A more verbose way to put this is "Requesting a string with a value that 
 is the same an an existing string does not necessarily result in reuse 
of the existing string but mey result in creation of a new, duplicate 
string.



>>> a = "a"*1000
>>> b = "a"*1000
>>> id(a),id(b)
(137143648, 137144680)
>>> a==b
True



interesting, I thought they were supposed to.


Reuse of immutable objects is entirely up to the implementation. 
CPython reuses small ints and identifier-like strings that it 'expects' 
   would otherwise be duplicated.  There is no reason to expect that 
the programmer will ask for 'a'*1000 again instead of explicitly reusing 
the existing object.  On the other hand, identifiers are almost always 
reused, often multiple times..  (Non-reuse may even by a bug!.)



Are you joking? two objects == two ids. if not i would dump Python
forever!


Me too, but see rewording.


Do you think Vector(0,0,0) and Vector(0,0,0) would have the same id?


If the instances of Vector are immutable, possibly yes.
If Vector(0,0,0) were typically called hundreds of times within a 
program, it might be worthwhile for the Vector class to pre-allocate one 
instance with that value and return it for each of the hundreds of 
calls.  That would be an implementation decision, which could be changed 
with experience.


Similarly, if one is populating a LARGE structure with duplicate values, 
it may be worthwhile to cache values that are not cached by the interpreter.


Terry Jan Reedy

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


Re: strange problem with Py2exe

2009-03-11 Thread Mike Driscoll
On Mar 11, 9:37 am, sf409...@gmail.com wrote:
> Hello all,
> in the past I've used Py2exe without any problem, but now I have this
> strange difficulty.
> In my computer I have  python 2.6,  py2exe for python 2.6 and the
> distutils, but when I do:
>
> from distutils.core import setup
> import py2exe
> setup(console=['hello.py'])
>
> ( like written in:  http://www.py2exe.org/index.cgi/Tutorial)
>
> at the end (at the command 'setup') all exits from python and I am
> again in DOS.
> (The same occurs when I use a file: e.g.  python 1.py)
>
> Where do I go wrong?
>
> Thanks

Re-post to the py2exe mailing list, but CM is probably correct. The
last I heard, compiling with 2.6 had some added complications. You
could also check the archives of this list AND the py2exe list. I'm
pretty sure there have been posts on this multiple times within a few
weeks of 2.6's release.

Here's a link to py2exe's list and archives:
https://lists.sourceforge.net/lists/listinfo/py2exe-users

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


Re: Why is lambda allowed as a key in a dict?

2009-03-11 Thread r
On Mar 11, 3:40 pm, Craig Allen  wrote:
> On Mar 10, 1:39 pm, Paul Rubin  wrote:
>
> > Craig Allen  writes:
> > > it raises an interesting question about why doesn't it.  I can think
> > > of practical answers to that, obviously, but in principle, if a
> > > function compiles to exactly the same byte code, you obviously do not
> > > need two copies of it, and like strings shouldn't an identical
> > > function have the same id?
>
> > Identical strings don't necessarily have the same id:
>
> >     >>> a = "a"*1000
> >     >>> b = "a"*1000
> >     >>> id(a),id(b)
> >     (137143648, 137144680)
> >     >>> a==b
> >     True
>
> interesting, I thought they were supposed to.

Are you joking? two objects == two ids. if not i would dump Python
forever!

Do you think Vector(0,0,0) and Vector(0,0,0) would have the same id?
--
http://mail.python.org/mailman/listinfo/python-list


Re: strange problem with Py2exe

2009-03-11 Thread CM
On Mar 11, 10:37 am, sf409...@gmail.com wrote:
> Hello all,
> in the past I've used Py2exe without any problem, but now I have this
> strange difficulty.
> In my computer I have  python 2.6,  py2exe for python 2.6 and the
> distutils, but when I do:
>
> from distutils.core import setup
> import py2exe
> setup(console=['hello.py'])
>
> ( like written in:  http://www.py2exe.org/index.cgi/Tutorial)
>
> at the end (at the command 'setup') all exits from python and I am
> again in DOS.
> (The same occurs when I use a file: e.g.  python 1.py)
>
> Where do I go wrong?
>
> Thanks

I think the problem is w/ Python 2.6--see this comment:
http://www.nabble.com/Re%3A-Python-2.6-and-py2exe---the-exe-crashes-on-vista-p21658057.html

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


Re: Why is lambda allowed as a key in a dict?

2009-03-11 Thread Craig Allen
On Mar 10, 1:39 pm, Paul Rubin  wrote:
> Craig Allen  writes:
> > it raises an interesting question about why doesn't it.  I can think
> > of practical answers to that, obviously, but in principle, if a
> > function compiles to exactly the same byte code, you obviously do not
> > need two copies of it, and like strings shouldn't an identical
> > function have the same id?
>
> Identical strings don't necessarily have the same id:
>
>     >>> a = "a"*1000
>     >>> b = "a"*1000
>     >>> id(a),id(b)
>     (137143648, 137144680)
>     >>> a==b
>     True

interesting, I thought they were supposed to.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Visual Studio 2005 build of Python 2.4, 2.5 or 2.6

2009-03-11 Thread Christian Heimes
Terry Reedy wrote:
> Are you looking for pre-built binaries or the build files to  make your
> own?  PSF distributes 2.? to 2.5 binaries built with VS2003 and 2.6+
> binaries built with VS2008 (I believe) and the corresponding build
> files.  People have built with VS2005, but you will have to search
> harder (try Google).

You are correct, Terry.
The source tar.gz contain a build directory for VS 2005 in PCBuild8 (Py
2.5) or PC/VS8.0/ (2.6, 3.0). You can easily build your own Python
interpreter.

Christian

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


Re: calling class methods from class methods, help?

2009-03-11 Thread Terry Reedy

Oltmans wrote:

I've a multithreaded program in which I've to call class methods from
class methods. Here is how my code look like (excluding imports),. Any
help is highly appreciated.

#!/usr/bin/env python
class Requests(Thread):

def __init__(self, times):
Thread.__init__(self)
self.times=times
self.name=''
def run(self):

sites=['example.com','example1.com']
for i in range(0,self.times):
for site in sites:
self.name = site
self.html=SendRequest() # This line throws an error


You should (almost) always display the error traceback.  I suspect 
NameError: global 'SendRequest' not found.  You need 
Requests.SendRequest.  but...



def SendRequest(self): #A class method


If it were, then call the parameter 'cls', not 'self'.  But it is not a 
classmethod without @classmethod decorator.  but...



# it sends a request to website using mechanize library


Does this need to send the class rather than instance object to the 
website?  If not, better to leave it an instance method and use 
self.SendRequest above.  If the request uses instance variables, then it 
*must* be an instance method!


def startThis(times,reqs):

threads=[]
for i in range (0,reqs):
owner=Requests(times)
owner.start()
threads.append(owner)

for thread in threads:
thread.join()

if __name__=="__main__":
#I want to create 2 threads, each of them will execute twice. At
least that is the intention.
startThis(2,2)



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



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


Re: Visual Studio 2005 build of Python 2.4, 2.5 or 2.6

2009-03-11 Thread Terry Reedy

paul.baum...@googlemail.com wrote:

Hello,

I am a bit lost with all the possible builds of python on Windoze. I
am looking for a Visual Studio 2005 build of Python 2.4, 2.5 or 2.6
incl. debug build of the python24.lib e.g. python24_d.lib ?


Are you looking for pre-built binaries or the build files to  make your 
own?  PSF distributes 2.? to 2.5 binaries built with VS2003 and 2.6+ 
binaries built with VS2008 (I believe) and the corresponding build 
files.  People have built with VS2005, but you will have to search 
harder (try Google).


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


Re: functions - where to store them

2009-03-11 Thread Terry Reedy

plsulliv...@gmail.com wrote:

I have several functions which I would like to store in a different
directory so several programs can use them. I can't seem to find much
information about how to call a function if the function code is not
actually in the script itself.
The problem: do I have to cut and paste functions into a script or can
I store them in a directory and call them from a script in another
directory. If the latter is possible, how is this done? Thanks.


After you follow the other suggestions of read about 'module' and 
'package' If you want a module or package available to *all* 
programs (that run with a particular version/installation of Python), 
you can put your module or packages in the 'site-packages' directory. 
On Windows, this is a subdirectory of pythonxy/lib/


>>> import sys; sys.path
['C:\\Programs\\Python30\\Lib\\idlelib', 
'C:\\WINDOWS\\system32\\python30.zip', 'C:\\Programs\\Python30\\DLLs', 
'C:\\Programs\\Python30\\lib', 'C:\\Programs\\Python30\\lib\\plat-win', 
'C:\\Programs\\Python30', 'C:\\Programs\\Python30\\lib\\site-packages']


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


Re: Stopping SocketServer on Python 2.5

2009-03-11 Thread David George

On 2009-03-11 19:02:26 +, Falcolas  said:


On Mar 11, 12:28 pm, David George wrote:

On 2009-03-11 04:36:29 +, "Mark Tolonen"  s

aid:







"David George"  wrote in message
news:00150e67$0$27956$c3e8...@news.astraweb.com...

Hi guys,



I've been developing some code for a university project using Python.
We've been working on an existing codebase, cleaning it up and removin

g

dead wood.



We decided to make some changes to internal message handling by using

a

SocketServer, which worked great when we were using 2.6, as we could
simply call its shutdown() method when we wanted to stop it from
'serving forever'.



Unfortunately, we've now needed to downgrade to python 2.5 to
accomodate the libtorrent python bindings we need to use as part of th

e

project.



So, my question is, is there any way to stop a SocketServer that's bee

n

told to server forever in python 2.5?



Sure, derive a class from one of the classes in SocketServer, and
override the methods that implement the shutdown behavior in 2.6.



-Mark


Based on what you guys have said i've had a look at the code for
serve_forever() in both 2.5 and 2.6, and tried to create my own derived
class in this manner:

class MBThreadingTCPServer(SocketServer.ThreadingTCPServer):

    def __init__(self, address_tuple, handler):
        SocketServer.ThreadingTCPServer.__init__(self, address_tu

ple, handler)

        self.__serving = True

    def serve_forever(self):
        while self.__serving:
            SocketServer.ThreadingTCPServer.handle_request(se

lf)


    def shutdown(self):
        self.__serving = False

Don't worry about the MB thing, it's just related to the name of our proj

ect.


I don't think i've done this right, but i've tried to implement the
serve_forever() functionality in my derived class, and also add the
shutdown() method so i can stop it.

Does this appear to be the right way to do things?

Cheers,

Dave


More or less what I would do, though you should be able to call
self.handle_request. It's worth noting that handle_request generally
calls a blocking socket method, which means your self.__serving check
only happens the next time it handles a request.

~G


Yes, i've just noticed that this is the problem ... i've updated the 
code to work like this:


class MBTCPServer(SocketServer.TCPServer):

   def serve_until_stopped(self):
   self.serving = True
   self.has_shutdown = False
   while self.serving:
   self.handle_request()
   self.has_shutdown = True

   def shutdown(self):
   self.serving = False

Simply calling the base class constructor when i build it (i believe 
this is inferred).


Again, problem here is the issue of being unable to kill the server 
while it's waiting on a request. In theory, i could force it to 
continue by sending some sort of junk data with the method i use to 
stop the server, but that seems a bit hacky, don't you think?


Cheers,

Dave

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


Re: calling class methods from class methods, help?

2009-03-11 Thread Oltmans
On Mar 11, 11:00 pm, Piet van Oostrum  wrote:
>                     self.html=self.SendRequest()
> --

Thank you, everyone, for the help. Appreciate that.

> Piet van Oostrum 
> URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4]
> Private email: p...@vanoostrum.org- Hide quoted text -
>
> - Show quoted text -

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


Re: Stopping SocketServer on Python 2.5

2009-03-11 Thread Falcolas
On Mar 11, 12:28 pm, David George wrote:
> On 2009-03-11 04:36:29 +, "Mark Tolonen"  said:
>
>
>
>
>
> > "David George"  wrote in message
> >news:00150e67$0$27956$c3e8...@news.astraweb.com...
> >> Hi guys,
>
> >> I've been developing some code for a university project using Python.
> >> We've been working on an existing codebase, cleaning it up and removing
> >> dead wood.
>
> >> We decided to make some changes to internal message handling by using a
> >> SocketServer, which worked great when we were using 2.6, as we could
> >> simply call its shutdown() method when we wanted to stop it from
> >> 'serving forever'.
>
> >> Unfortunately, we've now needed to downgrade to python 2.5 to
> >> accomodate the libtorrent python bindings we need to use as part of the
> >> project.
>
> >> So, my question is, is there any way to stop a SocketServer that's been
> >> told to server forever in python 2.5?
>
> > Sure, derive a class from one of the classes in SocketServer, and
> > override the methods that implement the shutdown behavior in 2.6.
>
> > -Mark
>
> Based on what you guys have said i've had a look at the code for
> serve_forever() in both 2.5 and 2.6, and tried to create my own derived
> class in this manner:
>
> class MBThreadingTCPServer(SocketServer.ThreadingTCPServer):
>
>     def __init__(self, address_tuple, handler):
>         SocketServer.ThreadingTCPServer.__init__(self, address_tuple, handler)
>         self.__serving = True
>
>     def serve_forever(self):
>         while self.__serving:
>             SocketServer.ThreadingTCPServer.handle_request(self)
>
>     def shutdown(self):
>         self.__serving = False
>
> Don't worry about the MB thing, it's just related to the name of our project.
>
> I don't think i've done this right, but i've tried to implement the
> serve_forever() functionality in my derived class, and also add the
> shutdown() method so i can stop it.
>
> Does this appear to be the right way to do things?
>
> Cheers,
>
> Dave

More or less what I would do, though you should be able to call
self.handle_request. It's worth noting that handle_request generally
calls a blocking socket method, which means your self.__serving check
only happens the next time it handles a request.

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


Re: Stopping SocketServer on Python 2.5

2009-03-11 Thread David George

On 2009-03-11 04:36:29 +, "Mark Tolonen"  said:



"David George"  wrote in message 
news:00150e67$0$27956$c3e8...@news.astraweb.com...

Hi guys,

I've been developing some code for a university project using Python. 
We've been working on an existing codebase, cleaning it up and removing 
dead wood.


We decided to make some changes to internal message handling by using a 
SocketServer, which worked great when we were using 2.6, as we could 
simply call its shutdown() method when we wanted to stop it from 
'serving forever'.


Unfortunately, we've now needed to downgrade to python 2.5 to 
accomodate the libtorrent python bindings we need to use as part of the 
project.


So, my question is, is there any way to stop a SocketServer that's been 
told to server forever in python 2.5?


Sure, derive a class from one of the classes in SocketServer, and 
override the methods that implement the shutdown behavior in 2.6.


-Mark


Based on what you guys have said i've had a look at the code for 
serve_forever() in both 2.5 and 2.6, and tried to create my own derived 
class in this manner:


class MBThreadingTCPServer(SocketServer.ThreadingTCPServer):

   def __init__(self, address_tuple, handler):
   SocketServer.ThreadingTCPServer.__init__(self, address_tuple, handler)
   self.__serving = True

   def serve_forever(self):
   while self.__serving:
   SocketServer.ThreadingTCPServer.handle_request(self)

   def shutdown(self):
   self.__serving = False

Don't worry about the MB thing, it's just related to the name of our project.

I don't think i've done this right, but i've tried to implement the 
serve_forever() functionality in my derived class, and also add the 
shutdown() method so i can stop it.


Does this appear to be the right way to do things?

Cheers,

Dave

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


Re: Problem with os.chdir()

2009-03-11 Thread van Asselt
Hello,

In order to prevent this type of problems, I alway do the following:

import path

path = something
path = os.path.normpath(path)
os.chdir(path)

This prevents a lot of problems for me.

Regards,
Henk

"Tim Golden"  wrote in message 
news:mailman.1646.1236751732.11746.python-l...@python.org...
> venutaurus...@gmail.com wrote:
>> Hello all,
>>I am writing a python script which has to access deep paths
>> then supported normally by the Windows OS (>255). So I am appending "\
>> \?\" to do so. But when I use the path in the above fashion with
>> os.chdir() it is unable to recognize my folder and throwing an error:
>>
>> Traceback (most recent call last):
>>   File "C:\JPDump\test.py", line 31, in 
>> renameStubs(file)
>>   File "C:\JPDump\test.py", line 15, in renameStubs
>> os.chdir (path)
>> WindowsError: [Error 123] The filename, directory name, or volume
>> label syntax is incorrect: '\\?\\C:\\TestDataSet\
>> \Many_Files_1_1KB_FIles\\001_0009_1000 FILES\\'
>>
>> The value of my path variable is
>> \?\C:\TestDataSet\Many_Files_1_1KB_FIles\001_0009_1000 FILES\
>
>
> There need to be two backslashes at the beginning:
>
> \\?\C:\TEST.FILES\
>
> Note the double backslash before the question mark.
>
> TJG 


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


Re: "Battleship" style game

2009-03-11 Thread Shawn Milochik
Thanks for the tips, everybody.

I've cleaned it up, and learned some useful things from your comments
and the reading they led to.

http://shawnmilo.com/ships/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Visual Studio 2005 build of Python 2.4, 2.5 or 2.6

2009-03-11 Thread Martin v. Löwis
> I am a bit lost with all the possible builds of python on Windoze. I
> am looking for a Visual Studio 2005 build of Python 2.4, 2.5 or 2.6
> incl. debug build of the python24.lib e.g. python24_d.lib ?

What's the problem with creating one yourself?

Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: calling class methods from class methods, help?

2009-03-11 Thread Piet van Oostrum
> Oltmans  (O) escribió:

>O> I've a multithreaded program in which I've to call class methods from
>O> class methods. Here is how my code look like (excluding imports),. Any
>O> help is highly appreciated.

>O> #!/usr/bin/env python
>O> class Requests(Thread):

>O> def __init__(self, times):
>O> Thread.__init__(self)
>O> self.times=times
>O> self.name=''
>O> def run(self):

>O> sites=['example.com','example1.com']
>O> for i in range(0,self.times):
>O> for site in sites:
>O> self.name = site
>O> self.html=SendRequest() # This line throws an error

self.html=self.SendRequest()
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Stopping SocketServer on Python 2.5

2009-03-11 Thread Falcolas
On Mar 10, 7:19 pm, David George  wrote:
> So, my question is, is there any way to stop a SocketServer that's been
> told to server forever in python 2.5?

serve_forever, in python 2.5, is simply coded as:

while 1:
self.handle_request()

So, instead of calling serve_forever, call handle_request in your own
loop with a shutdown flag. Assuming, of course, that you aren't using
the Forking server, in which case things get more interesting.

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


Re: factory functions & methods

2009-03-11 Thread Piet van Oostrum
> Aaron Brady  (AB) wrote:

>AB> Hello,
>AB> I am creating a container.  I have some types which are built to be
>AB> members of the container.  The members need to know which container
>AB> they are in, as they call methods on it, such as finding other
>AB> members.  I want help with the syntax to create the members.
>AB> Currently, the container has to be a parameter to the instantiation
>AB> methods.  I want the option to create members with attribute syntax
>AB> instead.

>AB> Currently, I have:

>AB> cA= Container( )
>AB> obA= SomeType( cA )
>AB> obB= OtherType( cA, otherarg )

>AB> I want:

>AB> cA= Container( )
>AB> obA= cA.SomeType( )
>AB> obB= cA.OtherType( otherarg )

>AB> What are my options?

>AB> P.S.  The container and members are C extension types, not pure Python.

You could do something like this (translated to C)

class Container(object):
  def __init__(self):
self.items = []
  def add(self, item):
self.items.append(item)
  def SomeType(self):
  newobj = SomeType()
  self.add(newobj)
  def OtherType(self, arg):
  newobj = OtherType(arg)
  self.add(newobj)
  
class SomeType(object):
  def __init__(self):
  pass
  
class OtherType(SomeType):
  def __init__(self, arg):
SomeType.__init__(self)
self.x = arg

cA = Container()
obA = cA.SomeType()
obB = cA.OtherType(5)
print cA.items

-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: calling class methods from class methods, help?

2009-03-11 Thread Chris Rebert
On Wed, Mar 11, 2009 at 10:08 AM, Oltmans  wrote:
> I've a multithreaded program in which I've to call class methods from
> class methods.

Um, those are instance methods, not class methods. Class methods take
the class itself as an argument (the parameter is typically named
"cls" instead of "self") and are defined with the help of the
classmethod() function, which is not the case in your code.

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: calling class methods from class methods, help?

2009-03-11 Thread MRAB

Oltmans wrote:

I've a multithreaded program in which I've to call class methods from
class methods. Here is how my code look like (excluding imports),. Any
help is highly appreciated.

#!/usr/bin/env python
class Requests(Thread):

def __init__(self, times):
Thread.__init__(self)
self.times=times
self.name=''
def run(self):

sites=['example.com','example1.com']
for i in range(0,self.times):
for site in sites:
self.name = site
self.html=SendRequest() # This line throws an error

Should be:
self.html = self.SendRequest()



def SendRequest(self): #A class method
# it sends a request to website using mechanize library

def startThis(times,reqs):

threads=[]
for i in range (0,reqs):
owner=Requests(times)
owner.start()
threads.append(owner)

for thread in threads:
thread.join()

if __name__=="__main__":
#I want to create 2 threads, each of them will execute twice. At
least that is the intention.
startThis(2,2)



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


Re: No module named _sqlite3

2009-03-11 Thread gert
On Mar 9, 8:31 pm, gert  wrote:
> Testing 3.1 i get this with 3.0 it works
>
> python/lib/python3.1/sqlite3/dbapi2.py", line 27, in ,
> ImportError:No module named _sqlite3,

never mind had some include problems during compiling, nothing to do
with 3.1
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with string format

2009-03-11 Thread Terry Reedy

Mike314 wrote:

Hello,

   I have a strange problem with the string format:


'%s %s %s %s %s' % ['01', '02', '03', '04', '05']

Traceback (most recent call last):
  File "", line 1, in 
TypeError: not enough arguments for format string

But as soon I use tuple it is working:

'%s %s %s %s %s' % ('01', '02', '03', '04', '05')

'01 02 03 04 05'


What is the problem and how can I still use list?


This sort of confusion between object as object and object as container 
of objects was one of the reasons for the development of the new 
str.format function.  Within a call, [1,2,3] is one argument matching 
one field.  *[1,2,3], for instance, becomes three arguments matching 
three fields.


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


Re: calling class methods from class methods, help?

2009-03-11 Thread Oltmans
On Mar 11, 10:08 pm, Oltmans  wrote:
>                 self.html=SendRequest() # This line throws an error

and error says
NameError: global name '_Requests_SendRequest' is not defined.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with os.chdir()

2009-03-11 Thread Tim Golden

Hendrik van Rooyen wrote:

"Tim Golden"  wrote:


Well, a little bit of experimentation shows that you can
*create* paths this deep (say, with os.mkdir). But you
can't actually set the current directory to it. So the


Is this also true if you try to go there by a succession
of shorter hops of the ./next_level kind?

- Hendrik



Yep. Seems to be. You reach a certain point and presumably
the internal "this is where I am" buffer runs out of oomph.

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


calling class methods from class methods, help?

2009-03-11 Thread Oltmans
I've a multithreaded program in which I've to call class methods from
class methods. Here is how my code look like (excluding imports),. Any
help is highly appreciated.

#!/usr/bin/env python
class Requests(Thread):

def __init__(self, times):
Thread.__init__(self)
self.times=times
self.name=''
def run(self):

sites=['example.com','example1.com']
for i in range(0,self.times):
for site in sites:
self.name = site
self.html=SendRequest() # This line throws an error

def SendRequest(self): #A class method
# it sends a request to website using mechanize library

def startThis(times,reqs):

threads=[]
for i in range (0,reqs):
owner=Requests(times)
owner.start()
threads.append(owner)

for thread in threads:
thread.join()

if __name__=="__main__":
#I want to create 2 threads, each of them will execute twice. At
least that is the intention.
startThis(2,2)



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


Re: Problem with os.chdir()

2009-03-11 Thread Hendrik van Rooyen
"Tim Golden"  wrote:

> Well, a little bit of experimentation shows that you can
> *create* paths this deep (say, with os.mkdir). But you
> can't actually set the current directory to it. So the

Is this also true if you try to go there by a succession
of shorter hops of the ./next_level kind?

- Hendrik

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


Python-URL! - weekly Python news and links (Mar 11)

2009-03-11 Thread Gabriel Genellina
QOTW:  "[Perhaps] it sounds [as though] I'm saying that most prospective users
of OSS [open-source software] can't even manage to download it.  Let me be
clear: that is exactly what I am saying." - Patrick McKenzie

http://www.kalzumeus.com/2009/03/07/how-to-successfully-compete-with-open-source-software/


New itertool candidate: like groupby but edge-triggered (or
event-triggered):
http://groups.google.com/group/comp.lang.python/t/d364e7b16bf151c7/

Is python worth learning as a second language?
http://groups.google.com/group/comp.lang.python/t/c444c1229aed90c1/

Other language used to have significant indentation, but is now
considering alternatives to allow multiline expressions (like a
multiline lambda in Python):
http://groups.google.com/group/comp.lang.python/t/52dcdb09b4d73915/

Enumerating all modules imported by a script:
http://groups.google.com/group/comp.lang.python/t/86759676867f18e8/

Several attempts to improve a code fragment involving lists, repeated
elements, and sorting:
http://groups.google.com/group/comp.lang.python/t/453f1c803b8a78e2/

Why are some strings automatically interned, and not other?
http://groups.google.com/group/comp.lang.python/t/e4daccae7e77fb0e/

Is it legal to modify an exception before re-raising it?
http://groups.google.com/group/comp.lang.python/t/f7a647405fd48f5b/

PHP has "==" and "===", but they do NOT behave the same as Python's
"==" and "is" operators
http://groups.google.com/group/comp.lang.python/t/a697da8a6885d87f/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish "the efforts of Python enthusiats":
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the "Planet" sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.
http://groups.google.com/group/comp.lang.python.announce/topics

Python411 indexes "podcasts ... to help people learn Python ..."
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donations/

The Summary of Python Tracker Issues is an automatically generated
report summarizing new bugs, closed ones, and patch submissions. 

http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://code.activestate.com/recipes/langs/python/

Many Python conferences around the world are in preparation.
Watch this space for links to them.

Among several Python-oriented RSS/RDF feeds available, see:
http://www.python.org/channews.rdf
For more, see:
http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all
The old Python "To-Do List" now lives principally in a
SourceForge reincarnation.
http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse
http://www.python.org/dev/peps/pep-004

Read a content file from a P7M

2009-03-11 Thread Luca
Hi all.

There is standard or sugested way in python to read the content of a P7M file?

I don't need no feature like verify sign, or sign using a certificate.
I only need to extract the content file of the p7m (a doc, a pdf, ...)

Thanks!

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


Visual Studio 2005 build of Python 2.4, 2.5 or 2.6

2009-03-11 Thread paul.baum...@googlemail.com
Hello,

I am a bit lost with all the possible builds of python on Windoze. I
am looking for a Visual Studio 2005 build of Python 2.4, 2.5 or 2.6
incl. debug build of the python24.lib e.g. python24_d.lib ?

Any hints are appreciated.

Paul

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


Re: UnicodeEncode Error ?

2009-03-11 Thread Lie Ryan

Rama Vadakattu wrote:

While doing the below

1) fetch  html page
2) extract title using BeatifulSoup
3) Save into the database.

iam getting the below error (at the bottom).

Few observations which i had:
 1) type of variable which holds this title is 
 2) iam getting this problem when the title has character whose
ordinal value > 128

I searched in google and tried various suggestions but none of them is
working.And also i couldnot able to understand the rootcause for such
a kind of behaviour.


What's the title of the feed. I guess it contains non-ASCII character. 
Try encoding the title with a proper encoding that can handle the 
title's character set (utf-8 is a good choice), then save it again to 
the database.

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


UnicodeEncode Error ?

2009-03-11 Thread Rama Vadakattu
While doing the below

1) fetch  html page
2) extract title using BeatifulSoup
3) Save into the database.

iam getting the below error (at the bottom).

Few observations which i had:
 1) type of variable which holds this title is 
 2) iam getting this problem when the title has character whose
ordinal value > 128

I searched in google and tried various suggestions but none of them is
working.And also i couldnot able to understand the rootcause for such
a kind of behaviour.

What will be the root cause for such a kind of problem?Any hint on how
to resolve this error?

~~~
Error
--
Traceback (most recent call last):
  File "fetchcron.py", line 11, in 
cmanager.triggerfetchFeed()
  File "/home/rama/djangoprojects/socialreader/views.py", line 40, in
triggerfetchFeed
self.fetchFeed(furl)
  File "/home/rama/djangoprojects/socialreader/views.py", line 102, in
fetchFeed
ne.save()
  File "/usr/lib/python2.5/site-packages/django/db/models/base.py",
line 311, in save
self.save_base(force_insert=force_insert,
force_update=force_update)
  File "/usr/lib/python2.5/site-packages/django/db/models/base.py",
line 383, in save_base
result = manager._insert(values, return_id=update_pk)
  File "/usr/lib/python2.5/site-packages/django/db/models/manager.py",
line 138, in _insert
return insert_query(self.model, values, **kwargs)
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py",
line 894, in insert_query
return query.execute_sql(return_id)
  File "/usr/lib/python2.5/site-packages/django/db/models/sql/
subqueries.py", line 309, in execute_sql
cursor = super(InsertQuery, self).execute_sql(None)
  File "/usr/lib/python2.5/site-packages/django/db/models/sql/
query.py", line 1734, in execute_sql
cursor.execute(sql, params)
  File "/usr/lib/python2.5/site-packages/django/db/backends/util.py",
line 19, in execute
return self.cursor.execute(sql, params)
  File "/usr/lib/python2.5/site-packages/django/db/backends/mysql/
base.py", line 83, in execute
return self.cursor.execute(query, args)
  File "/var/lib/python-support/python2.5/MySQLdb/cursors.py", line
151, in execute
query = query % db.literal(args)
  File "/var/lib/python-support/python2.5/MySQLdb/connections.py",
line 247, in literal
return self.escape(o, self.encoders)
  File "/var/lib/python-support/python2.5/MySQLdb/connections.py",
line 180, in string_literal
return db.string_literal(obj)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xc9' in
position 1: ordinal not in range(128)
---
--
http://mail.python.org/mailman/listinfo/python-list


Re: functions - where to store them

2009-03-11 Thread Lie Ryan

plsulliv...@gmail.com wrote:

I have several functions which I would like to store in a different
directory so several programs can use them. I can't seem to find much
information about how to call a function if the function code is not
actually in the script itself.
The problem: do I have to cut and paste functions into a script or can
I store them in a directory and call them from a script in another
directory. If the latter is possible, how is this done? Thanks.


Yes of course. It is called module.

file: functioncoll.py

def foo(): pass
def bar(): pass

file program.py
import functioncoll

functioncoll.foo()


Note: functioncoll.py must be in your python search path. One way to 
easily ensure it is in the search path is to put functioncoll.py in the 
same directory as program.py


Note that all the usual tricks with import also works, like
from functioncoll import foo, bar
import functioncoll as fc
--
http://mail.python.org/mailman/listinfo/python-list


Re: functions - where to store them

2009-03-11 Thread plsullivan1
On Mar 11, 10:46 am, plsulliv...@gmail.com wrote:
> I have several functions which I would like to store in a different
> directory so several programs can use them. I can't seem to find much
> information about how to call a function if the function code is not
> actually in the script itself.
> The problem: do I have to cut and paste functions into a script or can
> I store them in a directory and call them from a script in another
> directory. If the latter is possible, how is this done? Thanks.

Nevermind... it's like buying something to replace what was lost only
to find the lost one.
--
http://mail.python.org/mailman/listinfo/python-list


Re: functions - where to store them

2009-03-11 Thread Marco Mariani

plsulliv...@gmail.com wrote:


I have several functions which I would like to store in a different
directory so several programs can use them. I can't seem to find much
information about how to call a function if the function code is not
actually in the script itself.


read the tutorial, look for "modules" and "packages"

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


Re: functions - where to store them

2009-03-11 Thread Gabriel Genellina

En Wed, 11 Mar 2009 12:46:05 -0200,  escribió:


I have several functions which I would like to store in a different
directory so several programs can use them. I can't seem to find much
information about how to call a function if the function code is not
actually in the script itself.
The problem: do I have to cut and paste functions into a script or can
I store them in a directory and call them from a script in another
directory. If the latter is possible, how is this done? Thanks.


I suggest you read the Python tutorial at http://docs.python.org/tutorial
In particular, you're looking for "modules", and they're covered at  
http://docs.python.org/tutorial/modules.html


"""If you quit from the Python interpreter and enter it again, the  
definitions you have made (functions and variables) are lost. Therefore,  
if you want to write a somewhat longer program, you are better off using a  
text editor to prepare the input for the interpreter and running it with  
that file as input instead. This is known as creating a script. As your  
program gets longer, you may want to split it into several files for  
easier maintenance. You may also want to use a handy function that you’ve  
written in several programs without copying its definition into each  
program.


To support this, Python has a way to put definitions in a file and use  
them in a script or in an interactive instance of the interpreter. Such a  
file is called a module; definitions from a module can be imported into  
other modules or into the main module."""


--
Gabriel Genellina

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


Re: Set & Frozenset?

2009-03-11 Thread Lie Ryan

R. David Murray wrote:

Lie Ryan  wrote:

Matt Nordhoff wrote:

Alan G Isaac wrote:

Hans Larsen schrieb:
How could I "take" an elemment from a set or a frozenset 

On 3/8/2009 2:06 PM Diez B. Roggisch apparently wrote:

You iterate over them. If you only want one value, use
iter(the_set).next()

I recall a claim that

for result in myset: break

is the most efficient way to get one result.
Is this right? (It seems nearly the same.)

Alan Isaac

Checking Python 2.5 on Linux, your solution is much faster, but seeing
as they both come in under a microsecond, it hardly matters.


It's unexpected...

 >>> timeit.timeit('res=iter(myset).next()', 'myset=range(100)')
0.8894412399647
 >>> timeit.timeit('res=myset.next()', 'myset=range(100); 
myset=iter(myset)')

0.4916552002516
 >>> timeit.timeit('for res in myset: break', 'myset=range(100)')
0.3293300797699

I'd never expect that for-loop assignment is even faster than a 
precreated iter object (the second test)... but I don't think this 
for-looping variable leaking behavior is guaranteed, isn't it?


My guess would be that what's controlling the timing here is
name lookup.  Three in the first example, two in the second,
and one in the third.


You got it:

>>> timeit.timeit('res=myset()', 'myset=range(100); 
myset=iter(myset).next')

0.2646590399796


--

The following is a complete benchmark:

>>> timeit.timeit('res=iter(myset).next()', 'myset=range(1000)', 
number=1000)

8.514500200432

>>> timeit.timeit('res=myset.next()', 'myset=range(1000); 
myset=iter(myset)', number=1000)

4.550980280898

>>> timeit.timeit('for res in myset: break', 'myset=range(1000)', 
number=1000)

2.999421360421

>>> timeit.timeit('res=myset()', 'myset=range(1000); 
myset=iter(myset).next', number=1000)

2.222883241011

--
I also performed additional timing for overhead:

Local name lookup:
>>> timeit.timeit('myset', 'myset=range(100)', number=1000)
1.108640079865

Global name lookup:
>>> timeit.timeit('iter', number=1000)
1.814941079259

Attribute lookup:
>>> timeit.timeit('myset.next', 'myset=range(1000); 
myset=iter(myset)', number=1000)

3.301133397987

Combined multiple name lookup that troubled first test
>>> timeit.timeit('iter(myset).next', 'myset=range(1000)', 
number=1000)

6.559937480305

Creating iterables:
>>> timeit.timeit('iter(myset)', 'myset=range(100)', number=1000)
4.25940671788

--
So adjusting the overheads:

Attribute lookup:
>>> timeit.timeit('myset.next', 'myset=range(1000); 
myset=iter(myset)', number=1000)

3.301133397987
The timing for Attribute also include a local name lookup (myset), so 
the real attribute lookup time shold be:

3.301133397987 - 1.108640079865 = 2.192493318122

Creating iterables:
>>> timeit.timeit('iter(myset)', 'myset=range(100)', number=1000)
4.25940671788
Creating iterable involve global name lookup, so the real time should be:
4.25940671788 - 1.814941079259 = 2.65638621

--
To summarize the adjusted overheads:

Local name lookup: 1.108640079865
Global name lookup: 1.814941079259
Attribute lookup: 2.192493318122
Creating iterables: 2.65638621

--
Back to the problem, now we'll be adjusting the timing of each codes:
'res=iter(myset).next()': 8.514500200432
Adjusting with the "Combined multiple name lookup"
8.514500200432 - 6.559937480305 = 1.954562720126
Another way to do the adjustment:
Adjusting global name lookup (iter):
8.514500200432 - 1.814941079259 = 6.699559121172
Adjusting iterable creation:
6.699559121172 - 2.65638621 = 4.255093482551
Adjusting attribute lookup:
4.255093482551 - 2.192493318122 = 2.062600164429

'res=myset.next()': 4.550980280898
Adjusting with |unadjusted| attribute lookup:
4.550980280898 - 3.301133397987 = 1.249846882911
Another way to do the adjustment:
Adjusting with local name lookup:
4.550980280898 - 1.108640079865 = 3.442340201033
Adjusting with attribute lookup:
3.442340201033 - 2.192493318122 = 1.249846882911

'for res in myset: break': 2.999421360421
Adjusting for local name lookup (myset):
2.999421360421 - 1.108640079865 = 1.890781280556

'res=myset()': 2.222883241011
Adjusting for local name lookup
2.222883241011 - 1.108640079865 = 1.114243161146

--

To summarize:
'res=iter(myset).next()': 1.954562720126 / 2.062600164429
'res=myset.next()': 1.249846882911 / 1.249846882911
'for res in myset: break': 1.890781280556
'res=myset()': 1.114243161146

--

To conclude, 'for res in myset: break' is actually not much faster than 
'res=iter(myset).next()' except the former saves a lot of name lookup. 

functions - where to store them

2009-03-11 Thread plsullivan1
I have several functions which I would like to store in a different
directory so several programs can use them. I can't seem to find much
information about how to call a function if the function code is not
actually in the script itself.
The problem: do I have to cut and paste functions into a script or can
I store them in a directory and call them from a script in another
directory. If the latter is possible, how is this done? Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


strange problem with Py2exe

2009-03-11 Thread sf409777
Hello all,
in the past I've used Py2exe without any problem, but now I have this
strange difficulty.
In my computer I have  python 2.6,  py2exe for python 2.6 and the
distutils, but when I do:

from distutils.core import setup
import py2exe
setup(console=['hello.py'])

( like written in:   http://www.py2exe.org/index.cgi/Tutorial )

at the end (at the command 'setup') all exits from python and I am
again in DOS.
(The same occurs when I use a file: e.g.  python 1.py)

Where do I go wrong?

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


Re: Behaviour of os.rename()

2009-03-11 Thread venutaurus...@gmail.com
On Mar 11, 7:27 pm, Emile van Sebille  wrote:
> venutaurus...@gmail.com wrote:
> > Hello all,
> >             I got a suspicion on the behaviour of os.rename
> > (src,dst).If the src is the path of a file and dst is a new filename
> > this os.rename() function is infact creating a new file with the dst
> > name in the current working directory and leaving the src as it is. Is
> > this the expected behavior? If i want the actual source file in its
> > orignal location to be renamed without doing os.chdir() to that
> > directory, is that possible?
>
> > Ex: if my script ren.py contains the following code:
>
> > os.rename("C:\\Folder1\\Folder2\\file1,file2)
>
> os.rename("C:\\Folder1\\Folder2\\file1","C:\\Folder1\\Folder2\\file2")
>
> Emile

Thank you,
It worked :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Behaviour of os.rename()

2009-03-11 Thread venutaurus...@gmail.com
On Mar 11, 7:20 pm, Tim Golden  wrote:
> venutaurus...@gmail.com wrote:
> > Hello all,
> >             I got a suspicion on the behaviour of os.rename
> > (src,dst).If the src is the path of a file and dst is a new filename
> > this os.rename() function is infact creating a new file with the dst
> > name in the current working directory and leaving the src as it is. Is
> > this the expected behavior? If i want the actual source file in its
> > orignal location to be renamed without doing os.chdir() to that
> > directory, is that possible?
>
> > Ex: if my script ren.py contains the following code:
>
> > os.rename("C:\\Folder1\\Folder2\\file1,file2)
>
> >               and my ren.py is in the folder D:\. Now if I run this
> > script, it is creating file2 in D:\ but I want it in C:
> > \Folder1\Folder2. is that possible?
>
> >             When I checked the normal Windows rename function, it is
> > working to my expectations but I can't use it because my file is in a
> > deep path (>255) which Windows won't support.
>
> os.rename on windows calls the Windows MoveFile API:
>
>  http://msdn.microsoft.com/en-us/library/aa365239(VS.85).aspx
>
> Have a look at the details on that page to see what
> the limitations / actions are. But remember -- as I've
> indicated elsewhere -- to use the ur"\\?\c:\..." form
> of the file names.
>
> And let us know if that works :)
>
> TJG

That actually was an illustration. As you've told in another chain, it
isn't working even after appending "\\?\"

Thank you,
Venu
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with os.chdir()

2009-03-11 Thread Gabriel Genellina
En Wed, 11 Mar 2009 11:59:57 -0200, venutaurus...@gmail.com  
 escribió:

On Mar 11, 6:41 pm, Tim Golden  wrote:

venutaurus...@gmail.com wrote:
> On Mar 11, 5:19 pm, Tim Golden  wrote:

Well, the source for os.chdir under Windows uses the Win32
SetCurrentDirectoryW API as expected. What is not expected
is that the MS docs for that function:

 http://msdn.microsoft.com/en-us/library/aa365530(VS.85).aspx

still seem to suggest that you can't exceed MAX_PATH (ie 260)
characters. And indeed, attempting to do a mkdir at the command
line of something longer than that will also fail.

Hmmm.. maybe the usual advice for naming files \\?\... doesn't
apply to directory paths?

Do you have an already existing full pathname that long?


  My application demands me to create deep paths of (1023) long.
I've cross checked it and the folder actually exists.


As TJG said, it appears that you can create such deep path, and create and  
use files inside, but you can't chdir into it:


py> cien = '0123456789'*10
py> path = ur"\\?\c:\%s\%s\%s\%s\%s\%s\%s\%s\%s\%s\%s\%s" % ((cien,)*12)
py> len(path)
1218
py> os.mkdir(path) # after creating all intermediate directories
py> fn = os.path.join(path, 'x.txt')
py> f = open(fn, "w")
py> f.write("hello")
py> f.close()
py> open(fn).read()
'hello'
py> os.chdir(path)
Traceback (most recent call last):
  File "", line 1, in 
WindowsError: [Error 123] El nombre de archivo, directorio o etiqueta del  
volume
n no es vßlido:  
u'?\\c:\\012345678901234567890123456789012345678901234567890..."


So your application should always use absolute paths.

--
Gabriel Genellina

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


Re: Problem with os.chdir()

2009-03-11 Thread Tim Golden

venutaurus...@gmail.com wrote:

On Mar 11, 7:17 pm, Tim Golden  wrote:

venutaurus...@gmail.com wrote:

On Mar 11, 6:41 pm, Tim Golden  wrote:

venutaurus...@gmail.com wrote:

On Mar 11, 5:19 pm, Tim Golden  wrote:

Here is my code snippet which you will be interested in:

Indeed.

file = ur'\\?\C:\\TestDataSet\DeepPaths
\DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLe 
vel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepP 
athLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\ 
DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt'

And what happens if you remove that second double-backslash,
the one between C: and TestDataSet?
TJG

--- 
-
Even if I give the file path as below
file = ur'\\?\C:\TestDataSet\DeepPaths
\DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLe 
vel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepP 
athLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\ 
DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt'
I am still getting the exception:
Traceback (most recent call last):
  File "C:\JPDump\test.py", line 29, in 
renameStubs(file)
  File "C:\JPDump\test.py", line 12, in renameStubs
os.chdir (path)
WindowsError: [Error 206] The filename or extension is too long: u'\\\
\?\\C:\\TestDataSet\\DeepPaths\\DeepPathLevel01\\DeepPathLevel02\
\DeepPathLevel03\\DeepPathLevel04\\DeepPathLevel05\\DeepPathLevel06\
\DeepPathLevel07\\DeepPathLevel08\\DeepPathLevel09\\DeepPathLevel10\
\DeepPathLevel11\\DeepPathLevel12\\DeepPathLevel13\\DeepPathLevel14\
\DeepPathLevel15\\DeepPathLevel16\\'

Well, the source for os.chdir under Windows uses the Win32
SetCurrentDirectoryW API as expected. What is not expected
is that the MS docs for that function:
 http://msdn.microsoft.com/en-us/library/aa365530(VS.85).aspx
still seem to suggest that you can't exceed MAX_PATH (ie 260)
characters. And indeed, attempting to do a mkdir at the command
line of something longer than that will also fail.
Hmmm.. maybe the usual advice for naming files \\?\... doesn't
apply to directory paths?
Do you have an already existing full pathname that long?
TJG

Yes Sir,
  My application demands me to create deep paths of (1023) long.
I've cross checked it and the folder actually exists.

Well, a little bit of experimentation shows that you can
*create* paths this deep (say, with os.mkdir). But you
can't actually set the current directory to it. So the
next question is: do you actually need to be *in* that
directory, rather than simply to reference it?

In other words, you can do this (assuming you have a c:\temp):


import os
for i in range (1, 15):
  os.mkdir (ur"\\?\c:\temp\%s" % "\\".join (100 * "c" for j in range (i)))



But you can't then os.chdir to it. You're hitting the limits of
the OS. Try accessing files directly within the structure
you're using. (ie without chdir-ing there first).

TJG


Sir,
   My application has to rename a file in that folder.For that I had
to do a os.chdir() to that folder. Otherwise if I do a os.rename
(deeppath\file1,file2), it is creating a new file in the current
working directory with the new name and leaving the original file as
it is which is not intended :-(. So, can you suggest me any work
around for this?


Jus
t rename from and to with a full pathname (using the \\?\ bit):

os.rename (ur"\\?\c:\long\path\to\file.txt", 
ur"\\?\c:\long\path\to\newfile.txt")

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


Re: Behaviour of os.rename()

2009-03-11 Thread Emile van Sebille

venutaurus...@gmail.com wrote:

Hello all,
I got a suspicion on the behaviour of os.rename
(src,dst).If the src is the path of a file and dst is a new filename
this os.rename() function is infact creating a new file with the dst
name in the current working directory and leaving the src as it is. Is
this the expected behavior? If i want the actual source file in its
orignal location to be renamed without doing os.chdir() to that
directory, is that possible?

Ex: if my script ren.py contains the following code:

os.rename("C:\\Folder1\\Folder2\\file1,file2)


os.rename("C:\\Folder1\\Folder2\\file1","C:\\Folder1\\Folder2\\file2")

Emile

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


Re: Problem with os.chdir()

2009-03-11 Thread venutaurus...@gmail.com
On Mar 11, 7:17 pm, Tim Golden  wrote:
> venutaurus...@gmail.com wrote:
> > On Mar 11, 6:41 pm, Tim Golden  wrote:
> >> venutaurus...@gmail.com wrote:
> >>> On Mar 11, 5:19 pm, Tim Golden  wrote:
> > Here is my code snippet which you will be interested in:
>  Indeed.
> > file = ur'\\?\C:\\TestDataSet\DeepPaths
> > \DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLe
> >  
> > vel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepP
> >  
> > athLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\
> >  DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt'
>  And what happens if you remove that second double-backslash,
>  the one between C: and TestDataSet?
>  TJG
> >>> ---
> >>>  -
> >>> Even if I give the file path as below
> >>> file = ur'\\?\C:\TestDataSet\DeepPaths
> >>> \DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLe
> >>>  
> >>> vel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepP
> >>>  
> >>> athLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\
> >>>  DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt'
> >>> I am still getting the exception:
> >>> Traceback (most recent call last):
> >>>   File "C:\JPDump\test.py", line 29, in 
> >>>     renameStubs(file)
> >>>   File "C:\JPDump\test.py", line 12, in renameStubs
> >>>     os.chdir (path)
> >>> WindowsError: [Error 206] The filename or extension is too long: u'\\\
> >>> \?\\C:\\TestDataSet\\DeepPaths\\DeepPathLevel01\\DeepPathLevel02\
> >>> \DeepPathLevel03\\DeepPathLevel04\\DeepPathLevel05\\DeepPathLevel06\
> >>> \DeepPathLevel07\\DeepPathLevel08\\DeepPathLevel09\\DeepPathLevel10\
> >>> \DeepPathLevel11\\DeepPathLevel12\\DeepPathLevel13\\DeepPathLevel14\
> >>> \DeepPathLevel15\\DeepPathLevel16\\'
> >> Well, the source for os.chdir under Windows uses the Win32
> >> SetCurrentDirectoryW API as expected. What is not expected
> >> is that the MS docs for that function:
>
> >>  http://msdn.microsoft.com/en-us/library/aa365530(VS.85).aspx
>
> >> still seem to suggest that you can't exceed MAX_PATH (ie 260)
> >> characters. And indeed, attempting to do a mkdir at the command
> >> line of something longer than that will also fail.
>
> >> Hmmm.. maybe the usual advice for naming files \\?\... doesn't
> >> apply to directory paths?
>
> >> Do you have an already existing full pathname that long?
>
> >> TJG
>
> > Yes Sir,
> >       My application demands me to create deep paths of (1023) long.
> > I've cross checked it and the folder actually exists.
>
> Well, a little bit of experimentation shows that you can
> *create* paths this deep (say, with os.mkdir). But you
> can't actually set the current directory to it. So the
> next question is: do you actually need to be *in* that
> directory, rather than simply to reference it?
>
> In other words, you can do this (assuming you have a c:\temp):
>
> 
> import os
> for i in range (1, 15):
>   os.mkdir (ur"\\?\c:\temp\%s" % "\\".join (100 * "c" for j in range (i)))
>
> 
>
> But you can't then os.chdir to it. You're hitting the limits of
> the OS. Try accessing files directly within the structure
> you're using. (ie without chdir-ing there first).
>
> TJG

Sir,
   My application has to rename a file in that folder.For that I had
to do a os.chdir() to that folder. Otherwise if I do a os.rename
(deeppath\file1,file2), it is creating a new file in the current
working directory with the new name and leaving the original file as
it is which is not intended :-(. So, can you suggest me any work
around for this?

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


Re: Behaviour of os.rename()

2009-03-11 Thread Tim Golden

venutaurus...@gmail.com wrote:

Hello all,
I got a suspicion on the behaviour of os.rename
(src,dst).If the src is the path of a file and dst is a new filename
this os.rename() function is infact creating a new file with the dst
name in the current working directory and leaving the src as it is. Is
this the expected behavior? If i want the actual source file in its
orignal location to be renamed without doing os.chdir() to that
directory, is that possible?

Ex: if my script ren.py contains the following code:

os.rename("C:\\Folder1\\Folder2\\file1,file2)

  and my ren.py is in the folder D:\. Now if I run this
script, it is creating file2 in D:\ but I want it in C:
\Folder1\Folder2. is that possible?

When I checked the normal Windows rename function, it is
working to my expectations but I can't use it because my file is in a
deep path (>255) which Windows won't support.


os.rename on windows calls the Windows MoveFile API:

 http://msdn.microsoft.com/en-us/library/aa365239(VS.85).aspx

Have a look at the details on that page to see what
the limitations / actions are. But remember -- as I've
indicated elsewhere -- to use the ur"\\?\c:\..." form
of the file names.

And let us know if that works :)

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


Re: Problem with os.chdir()

2009-03-11 Thread Tim Golden

venutaurus...@gmail.com wrote:

On Mar 11, 6:41 pm, Tim Golden  wrote:

venutaurus...@gmail.com wrote:

On Mar 11, 5:19 pm, Tim Golden  wrote:

Here is my code snippet which you will be interested in:

Indeed.

file = ur'\\?\C:\\TestDataSet\DeepPaths
\DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLe 
vel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepP 
athLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\ 
DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt'

And what happens if you remove that second double-backslash,
the one between C: and TestDataSet?
TJG

--- 
-
Even if I give the file path as below
file = ur'\\?\C:\TestDataSet\DeepPaths
\DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLe 
vel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepP 
athLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\ 
DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt'
I am still getting the exception:
Traceback (most recent call last):
  File "C:\JPDump\test.py", line 29, in 
renameStubs(file)
  File "C:\JPDump\test.py", line 12, in renameStubs
os.chdir (path)
WindowsError: [Error 206] The filename or extension is too long: u'\\\
\?\\C:\\TestDataSet\\DeepPaths\\DeepPathLevel01\\DeepPathLevel02\
\DeepPathLevel03\\DeepPathLevel04\\DeepPathLevel05\\DeepPathLevel06\
\DeepPathLevel07\\DeepPathLevel08\\DeepPathLevel09\\DeepPathLevel10\
\DeepPathLevel11\\DeepPathLevel12\\DeepPathLevel13\\DeepPathLevel14\
\DeepPathLevel15\\DeepPathLevel16\\'

Well, the source for os.chdir under Windows uses the Win32
SetCurrentDirectoryW API as expected. What is not expected
is that the MS docs for that function:

 http://msdn.microsoft.com/en-us/library/aa365530(VS.85).aspx

still seem to suggest that you can't exceed MAX_PATH (ie 260)
characters. And indeed, attempting to do a mkdir at the command
line of something longer than that will also fail.

Hmmm.. maybe the usual advice for naming files \\?\... doesn't
apply to directory paths?

Do you have an already existing full pathname that long?

TJG


Yes Sir,
  My application demands me to create deep paths of (1023) long.
I've cross checked it and the folder actually exists.



Well, a little bit of experimentation shows that you can
*create* paths this deep (say, with os.mkdir). But you
can't actually set the current directory to it. So the
next question is: do you actually need to be *in* that
directory, rather than simply to reference it?

In other words, you can do this (assuming you have a c:\temp):


import os
for i in range (1, 15):
 os.mkdir (ur"\\?\c:\temp\%s" % "\\".join (100 * "c" for j in range (i)))



But you can't then os.chdir to it. You're hitting the limits of
the OS. Try accessing files directly within the structure
you're using. (ie without chdir-ing there first).

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


Behaviour of os.rename()

2009-03-11 Thread venutaurus...@gmail.com
Hello all,
I got a suspicion on the behaviour of os.rename
(src,dst).If the src is the path of a file and dst is a new filename
this os.rename() function is infact creating a new file with the dst
name in the current working directory and leaving the src as it is. Is
this the expected behavior? If i want the actual source file in its
orignal location to be renamed without doing os.chdir() to that
directory, is that possible?

Ex: if my script ren.py contains the following code:

os.rename("C:\\Folder1\\Folder2\\file1,file2)

  and my ren.py is in the folder D:\. Now if I run this
script, it is creating file2 in D:\ but I want it in C:
\Folder1\Folder2. is that possible?

When I checked the normal Windows rename function, it is
working to my expectations but I can't use it because my file is in a
deep path (>255) which Windows won't support.

Thanks in advance,
Venu.

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


Re: can python import class or module directly from a zip package

2009-03-11 Thread Gabriel Genellina

En Wed, 11 Mar 2009 11:47:54 -0200, Lorenzo  escribió:

On Mar 10, 2:13 pm, Flank  wrote:



can python import class or  module directly from  a zip package ,just
like jave does from jar package without extracting the class file into
directory

so far as i know ,python module should be unzip to file system in
order to use them,


After a little digging/googling, the answer came right from the docs:

http://docs.python.org/library/zipimport.html

I think that this module is just right what you need.


Note that you don't have to do anything special to use zipimport; it's  
enabled by default.
Just make sure your zip file name is present in sys.path, as if it were a  
directory.


--
Gabriel Genellina

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


Re: Problem with os.chdir()

2009-03-11 Thread venutaurus...@gmail.com
On Mar 11, 6:41 pm, Tim Golden  wrote:
> venutaurus...@gmail.com wrote:
> > On Mar 11, 5:19 pm, Tim Golden  wrote:
> >>> Here is my code snippet which you will be interested in:
> >> Indeed.
>
> >>> file = ur'\\?\C:\\TestDataSet\DeepPaths
> >>> \DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLe
> >>>  
> >>> vel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepP
> >>>  
> >>> athLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\
> >>>  DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt'
> >> And what happens if you remove that second double-backslash,
> >> the one between C: and TestDataSet?
>
> >> TJG
> > --- 
> > -
> > Even if I give the file path as below
>
> > file = ur'\\?\C:\TestDataSet\DeepPaths
> > \DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLe 
> > vel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepP 
> > athLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\ 
> > DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt'
>
> > I am still getting the exception:
>
> > Traceback (most recent call last):
> >   File "C:\JPDump\test.py", line 29, in 
> >     renameStubs(file)
> >   File "C:\JPDump\test.py", line 12, in renameStubs
> >     os.chdir (path)
> > WindowsError: [Error 206] The filename or extension is too long: u'\\\
> > \?\\C:\\TestDataSet\\DeepPaths\\DeepPathLevel01\\DeepPathLevel02\
> > \DeepPathLevel03\\DeepPathLevel04\\DeepPathLevel05\\DeepPathLevel06\
> > \DeepPathLevel07\\DeepPathLevel08\\DeepPathLevel09\\DeepPathLevel10\
> > \DeepPathLevel11\\DeepPathLevel12\\DeepPathLevel13\\DeepPathLevel14\
> > \DeepPathLevel15\\DeepPathLevel16\\'
>
> Well, the source for os.chdir under Windows uses the Win32
> SetCurrentDirectoryW API as expected. What is not expected
> is that the MS docs for that function:
>
>  http://msdn.microsoft.com/en-us/library/aa365530(VS.85).aspx
>
> still seem to suggest that you can't exceed MAX_PATH (ie 260)
> characters. And indeed, attempting to do a mkdir at the command
> line of something longer than that will also fail.
>
> Hmmm.. maybe the usual advice for naming files \\?\... doesn't
> apply to directory paths?
>
> Do you have an already existing full pathname that long?
>
> TJG

Yes Sir,
  My application demands me to create deep paths of (1023) long.
I've cross checked it and the folder actually exists.

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


Re: Is python worth learning as a second language?

2009-03-11 Thread ZikO

Well

What Can I say guys?

I really appreciate your help here. Thanks for your answers. I have read 
all of them :P. Yes. Thanks for the websites: Dive In Python and 
docs.python.org. And I most say I have been convinced to take it as 
another tool for the programmer.


PS. Tomasz, thanks for pl.comp.lang.python I have been there and even 
asked similar queastion =). Regards/Pozdrawiam

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


Re: can python import class or module directly from a zip package

2009-03-11 Thread Lorenzo
On Mar 10, 2:13 pm, Flank  wrote:
> can python import class or  module directly from  a zip package ,just
> like jave does from jar package without extracting the class file into
> directory
>
> so far as i know ,python module should be unzip to file system in
> order to use them,

After a little digging/googling, the answer came right from the docs:

http://docs.python.org/library/zipimport.html

I think that this module is just right what you need.

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


Re: Problem with os.chdir()

2009-03-11 Thread Tim Golden

venutaurus...@gmail.com wrote:

On Mar 11, 5:19 pm, Tim Golden  wrote:

Here is my code snippet which you will be interested in:

Indeed.


file = ur'\\?\C:\\TestDataSet\DeepPaths
\DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLe 
vel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepP 
athLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\ 
DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt'

And what happens if you remove that second double-backslash,
the one between C: and TestDataSet?

TJG


Even if I give the file path as below

file = ur'\\?\C:\TestDataSet\DeepPaths
\DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLevel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepPathLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt'

I am still getting the exception:

Traceback (most recent call last):
  File "C:\JPDump\test.py", line 29, in 
renameStubs(file)
  File "C:\JPDump\test.py", line 12, in renameStubs
os.chdir (path)
WindowsError: [Error 206] The filename or extension is too long: u'\\\
\?\\C:\\TestDataSet\\DeepPaths\\DeepPathLevel01\\DeepPathLevel02\
\DeepPathLevel03\\DeepPathLevel04\\DeepPathLevel05\\DeepPathLevel06\
\DeepPathLevel07\\DeepPathLevel08\\DeepPathLevel09\\DeepPathLevel10\
\DeepPathLevel11\\DeepPathLevel12\\DeepPathLevel13\\DeepPathLevel14\
\DeepPathLevel15\\DeepPathLevel16\\'




Well, the source for os.chdir under Windows uses the Win32
SetCurrentDirectoryW API as expected. What is not expected
is that the MS docs for that function:

 http://msdn.microsoft.com/en-us/library/aa365530(VS.85).aspx

still seem to suggest that you can't exceed MAX_PATH (ie 260)
characters. And indeed, attempting to do a mkdir at the command
line of something longer than that will also fail.

Hmmm.. maybe the usual advice for naming files \\?\... doesn't
apply to directory paths?

Do you have an already existing full pathname that long?

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


Re: elixir vs. storm

2009-03-11 Thread Bruno Desthuilliers

Dan Barbus a écrit :

Hi,

Anyone here compared elixir with storm? Both are sqlite declarative
wrappers (as far as I understood) and both seem to hide the
(unnecessary for what I want) SQL/data layer under pythonic wrappers.


elixir is a declarative layer over SQLAlchemy, which is a hi-level 
SQL/Python integration layer (and much more than an ORM). And it's in no 
way tied to SQLite (works as well with MySQL, Postgres and a couple 
other RDBMS).



I'm not trying to start a flamewar here (but I wanted to know if one
is more mature than the other, more pythonic, easier to use or
whatever ...

Also, are there any other alternatives for easily working with sqlite
in python?


There's a "low-level" DB-API compliant connector to SQLite. IIRC, it's 
even included in the stdlib now.

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


msiexec and python-2.6.1.msi

2009-03-11 Thread cjl
With previous versions of the Python Windows msi installer, for
example 2.5.4,
I could run the following command from the windows cmd prompt:

msiexec /a C:\python-2.5.4.msi /qn TARGETDIR=C:\python

This would result in a 'full' python installation in the C:\python
directory, inside of which I would find the (necessary) file
msvcr70.dll. Perhaps it was actually msvcr71.dll most recently, I
can't remember. Of
course, this would not register extensions, but I did not want it to.

When I try the same command with python-2.6.1.msi, the file
msvcr90.dll and the manifest file are not created in the python
directory, nor anywhere else on the system.

If, instead, I double click the python-2.6.1.msi installer, the
msvcr90.dll file is created. I have tried msiexec with '/a' and '/i'
command line switches, and every possible combination of options, all
to no avail.

I can't figure out if this is a regression, but it used to work.

I am basing my attempts on the following page:
http://www.python.org/download/releases/2.5/msi/

I could not find a similar page for the 2.6 release.

Can anyone point me in the right direction to figure out what I'm
doing wrong?

Thanks,
-cjlesh
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with os.chdir()

2009-03-11 Thread venutaurus...@gmail.com
On Mar 11, 5:19 pm, Tim Golden  wrote:
> > Here is my code snippet which you will be interested in:
>
> Indeed.
>
> > file = ur'\\?\C:\\TestDataSet\DeepPaths
> > \DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLe 
> > vel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepP 
> > athLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\ 
> > DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt'
>
> And what happens if you remove that second double-backslash,
> the one between C: and TestDataSet?
>
> TJG

Even if I give the file path as below

file = ur'\\?\C:\TestDataSet\DeepPaths
\DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLevel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepPathLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt'

I am still getting the exception:

Traceback (most recent call last):
  File "C:\JPDump\test.py", line 29, in 
renameStubs(file)
  File "C:\JPDump\test.py", line 12, in renameStubs
os.chdir (path)
WindowsError: [Error 206] The filename or extension is too long: u'\\\
\?\\C:\\TestDataSet\\DeepPaths\\DeepPathLevel01\\DeepPathLevel02\
\DeepPathLevel03\\DeepPathLevel04\\DeepPathLevel05\\DeepPathLevel06\
\DeepPathLevel07\\DeepPathLevel08\\DeepPathLevel09\\DeepPathLevel10\
\DeepPathLevel11\\DeepPathLevel12\\DeepPathLevel13\\DeepPathLevel14\
\DeepPathLevel15\\DeepPathLevel16\\'

Please help..
Thank you,
Venu M


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


blocked on futex

2009-03-11 Thread msoulier
Hello,

I'm using the Python packaged with CentOS 4.7, which is a patched
2.3.4. Yes, ancient but I can't do anything about it.

The problem is that my long-running process, which talks to PostgreSQL
via Django models, does a lot of reading and writing to and from the
disk and writes to a Unix domain socket is randomly locking up. I have
not found a consistent place in my code where this lock-up occurs, but
every time it does, an strace shows that it is sitting at an futex()
call, apparently waiting forever.

My first guess is that futex() is being used by pthread_mutex_lock()
for thread-safety. I'm not using threads but the interpreter was built
with threaded support AFAIK.

A step in the right direction would be appreciated, I'm at a loss on
this one. I'm currently trying to strace the entire run of the program
to gain some context when it locks up to find out what it was doing at
the time.

Cheers and thanks,
MIke
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with os.chdir()

2009-03-11 Thread Tim Golden

Here is my code snippet which you will be interested in:


Indeed.


file = ur'\\?\C:\\TestDataSet\DeepPaths
\DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLevel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepPathLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt'



And what happens if you remove that second double-backslash,
the one between C: and TestDataSet?

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


Re: Problem with os.chdir()

2009-03-11 Thread venutaurus...@gmail.com
On Mar 11, 5:02 pm, Tim Golden  wrote:
> venutaurus...@gmail.com wrote:
> > On Mar 11, 11:08 am, Tim Golden  wrote:
> >> venutaurus...@gmail.com wrote:
> >>> Hello all,
> >>>            I am writing a python script which has to access deep paths
> >>> then supported normally by the Windows OS (>255). So I am appending "\
> >>> \?\" to do so. But when I use the path in the above fashion with
> >>> os.chdir() it is unable to recognize my folder and throwing an error:
> >>> Traceback (most recent call last):
> >>>   File "C:\JPDump\test.py", line 31, in 
> >>>     renameStubs(file)
> >>>   File "C:\JPDump\test.py", line 15, in renameStubs
> >>>     os.chdir (path)
> >>> WindowsError: [Error 123] The filename, directory name, or volume
> >>> label syntax is incorrect: '\\?\\C:\\TestDataSet\
> >>> \Many_Files_1_1KB_FIles\\001_0009_1000 FILES\\'
> >>> The value of my path variable is
> >>> \?\C:\TestDataSet\Many_Files_1_1KB_FIles\001_0009_1000 FILES\
> >> There need to be two backslashes at the beginning:
>
> >> \\?\C:\TEST.FILES\
>
> >> Note the double backslash before the question mark.
>
> >> TJG
>
> > I've another situation where os.chdir() function failed. Please find
> > the traceback pasted below:
> > Traceback (most recent call last):
> >   File "C:\JPDump\test.py", line 29, in 
> >     renameStubs(file)
> >   File "C:\JPDump\test.py", line 12, in renameStubs
> >     os.chdir (path)
> > WindowsError: [Error 206] The filename or extension is too long: '\\?\
> > \C:\\TestDataSet\\DeepPaths\\DeepPathLevel01\\DeepPathLevel02\
> > \DeepPathLevel03\\DeepPathLevel04\\DeepPathLevel05\\DeepPathLevel06\
> > \DeepPathLevel07\\DeepPathLevel08\\DeepPathLevel09\\DeepPathLevel10\
> > \DeepPathLevel11\\DeepPathLevel12\\DeepPathLevel13\\DeepPathLevel14\
> > \DeepPathLevel15\\DeepPathLevel16\\'
>
> Try it as a unicode string:
>
> os.chdir (ur"\\?\c:\test...\deep...")
>
> TJG

Sorry.. even that failed:

Traceback (most recent call last):
  File "C:\JPDump\test.py", line 29, in 
renameStubs(file)
  File "C:\JPDump\test.py", line 12, in renameStubs
os.chdir (path)
WindowsError: [Error 206] The filename or extension is too long: u'\\\
\?\\C:TestDataSet\\DeepPaths\\DeepPathLevel01\\DeepPathLevel02\
\DeepPathLevel03\\DeepPathLevel04\\DeepPathLevel05\\DeepPathLevel06\
\DeepPathLevel07\\DeepPathLevel08\\DeepPathLevel09\\DeepPathLevel10\
\DeepPathLevel11\\DeepPathLevel12\\DeepPathLevel13\\DeepPathLevel14\
\DeepPathLevel15\\DeepPathLevel16\\'
---
Here is my code snippet which you will be interested in:

file = ur'\\?\C:\\TestDataSet\DeepPaths
\DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLevel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepPathLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt'
def renameStubs(file):
#e.write(u"\n"+strftime("%Y-%m-%d %H:%M:%S") +" we are in
renameStubs function \n")
drive = file.split(":")[0]
oldName = file.split("\\")[-1]
path = file.rstrip(oldName)
os.chdir (path)

renameStubs(file)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with os.chdir()

2009-03-11 Thread Tim Golden

venutaurus...@gmail.com wrote:

On Mar 11, 11:08 am, Tim Golden  wrote:

venutaurus...@gmail.com wrote:

Hello all,
   I am writing a python script which has to access deep paths
then supported normally by the Windows OS (>255). So I am appending "\
\?\" to do so. But when I use the path in the above fashion with
os.chdir() it is unable to recognize my folder and throwing an error:
Traceback (most recent call last):
  File "C:\JPDump\test.py", line 31, in 
renameStubs(file)
  File "C:\JPDump\test.py", line 15, in renameStubs
os.chdir (path)
WindowsError: [Error 123] The filename, directory name, or volume
label syntax is incorrect: '\\?\\C:\\TestDataSet\
\Many_Files_1_1KB_FIles\\001_0009_1000 FILES\\'
The value of my path variable is
\?\C:\TestDataSet\Many_Files_1_1KB_FIles\001_0009_1000 FILES\

There need to be two backslashes at the beginning:

\\?\C:\TEST.FILES\

Note the double backslash before the question mark.

TJG


I've another situation where os.chdir() function failed. Please find
the traceback pasted below:
Traceback (most recent call last):
  File "C:\JPDump\test.py", line 29, in 
renameStubs(file)
  File "C:\JPDump\test.py", line 12, in renameStubs
os.chdir (path)
WindowsError: [Error 206] The filename or extension is too long: '\\?\
\C:\\TestDataSet\\DeepPaths\\DeepPathLevel01\\DeepPathLevel02\
\DeepPathLevel03\\DeepPathLevel04\\DeepPathLevel05\\DeepPathLevel06\
\DeepPathLevel07\\DeepPathLevel08\\DeepPathLevel09\\DeepPathLevel10\
\DeepPathLevel11\\DeepPathLevel12\\DeepPathLevel13\\DeepPathLevel14\
\DeepPathLevel15\\DeepPathLevel16\\'


Try it as a unicode string:

os.chdir (ur"\\?\c:\test...\deep...")

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


Re: Problem with os.chdir()

2009-03-11 Thread venutaurus...@gmail.com
On Mar 11, 11:08 am, Tim Golden  wrote:
> venutaurus...@gmail.com wrote:
> > Hello all,
> >            I am writing a python script which has to access deep paths
> > then supported normally by the Windows OS (>255). So I am appending "\
> > \?\" to do so. But when I use the path in the above fashion with
> > os.chdir() it is unable to recognize my folder and throwing an error:
>
> > Traceback (most recent call last):
> >   File "C:\JPDump\test.py", line 31, in 
> >     renameStubs(file)
> >   File "C:\JPDump\test.py", line 15, in renameStubs
> >     os.chdir (path)
> > WindowsError: [Error 123] The filename, directory name, or volume
> > label syntax is incorrect: '\\?\\C:\\TestDataSet\
> > \Many_Files_1_1KB_FIles\\001_0009_1000 FILES\\'
>
> > The value of my path variable is
> > \?\C:\TestDataSet\Many_Files_1_1KB_FIles\001_0009_1000 FILES\
>
> There need to be two backslashes at the beginning:
>
> \\?\C:\TEST.FILES\
>
> Note the double backslash before the question mark.
>
> TJG

I've another situation where os.chdir() function failed. Please find
the traceback pasted below:
Traceback (most recent call last):
  File "C:\JPDump\test.py", line 29, in 
renameStubs(file)
  File "C:\JPDump\test.py", line 12, in renameStubs
os.chdir (path)
WindowsError: [Error 206] The filename or extension is too long: '\\?\
\C:\\TestDataSet\\DeepPaths\\DeepPathLevel01\\DeepPathLevel02\
\DeepPathLevel03\\DeepPathLevel04\\DeepPathLevel05\\DeepPathLevel06\
\DeepPathLevel07\\DeepPathLevel08\\DeepPathLevel09\\DeepPathLevel10\
\DeepPathLevel11\\DeepPathLevel12\\DeepPathLevel13\\DeepPathLevel14\
\DeepPathLevel15\\DeepPathLevel16\\'

Thanks in advance,
Venu Madhav.


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


elixir vs. storm

2009-03-11 Thread Dan Barbus
Hi,

Anyone here compared elixir with storm? Both are sqlite declarative
wrappers (as far as I understood) and both seem to hide the
(unnecessary for what I want) SQL/data layer under pythonic wrappers.

I'm not trying to start a flamewar here (but I wanted to know if one
is more mature than the other, more pythonic, easier to use or
whatever ...

Also, are there any other alternatives for easily working with sqlite
in python?

Thanks,
Dan
--
http://mail.python.org/mailman/listinfo/python-list


Re: Determining from which web page a cgi script is invoked?

2009-03-11 Thread davidgould
On Mar 10, 7:15 pm, cm  wrote:
> davidgo...@davidgould.com escribió:
>
> > Given a webpage test.html that has a form with a cgi script, how can
> > you determine inside the cgi script the name of the webpage that
> > invoked the script?
>
> > I have many different html pages that use a common cgi script for form
> > processing and want to determine the name of the webpage.
>
> quick&dirty: Add a hidden form var with the page/form name

Yes, I had considered this. Is there any way to quickly automate the
setting of this var to match the html page that contains it?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Determining from which web page a cgi script is invoked?

2009-03-11 Thread davidgould
On Mar 10, 7:15 pm, cm  wrote:
> davidgo...@davidgould.com escribió:
>
> > Given a webpage test.html that has a form with a cgi script, how can
> > you determine inside the cgi script the name of the webpage that
> > invoked the script?
>
> > I have many different html pages that use a common cgi script for form
> > processing and want to determine the name of the webpage.
>
> quick&dirty: Add a hidden form var with the page/form name

Yes, I had considered this. Is there any way to quickly automate the
setting of this var to match the html page that contains it?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ban Xah Lee

2009-03-11 Thread Craig Allen
> There you go: a 30-second psychological diagnosis by an
> electrical engineer based entirely on Usenet postings.  It
> doesn't get much more worthless than that...
>
> --
> Grant

rolf but interesting post nonetheless.  I have been really somewhat
fascinated by AS since I heard of it about a decade ago.  There are
many among us, with interesting ideas, occasionally savant level
insight into certain abstractions, which often they can not
communicate but which lie there for those that can communicate or come
to understand nonetheless.

having said that, none of this forgives rudeness or implies people
have to tolarate it due to a person's condition, or even due to trying
to help them achieve their potential (and thus get something
productive out of it ourselves as well)...  that is, if you have these
communications problems you have to realize it, thank god you are
functional, and just that alone will help you communicate.

me, also IANAP, also working from usenet and an asperger's book I read
(and google)...
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >