Re: Reading a large csv file

2009-06-23 Thread Terry Reedy

Mag Gam wrote:

Yes, the system has 64Gig of physical memory.


drool ;-).


What I meant was, is it possible to load to a hdf5 dataformat
(basically NumPy array) without reading the entire file at first? I
would like to splay to disk beforehand so it would be a bit faster
instead of having 2 copies in memory.


If you can write hdf5 a line at a time, you should be able to something like



for line in cvs:
  process line
  write hdf5 line

this assumes 1-1 lines.

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


Re: Measuring Fractal Dimension ?

2009-06-23 Thread Mark Dickinson
On Jun 23, 3:52 am, Steven D'Aprano
 wrote:
> On Mon, 22 Jun 2009 13:43:19 -0500, David C. Ullrich wrote:
> > In my universe the standard definition of "log" is different froim what
> > log means in a calculus class
>
> Now I'm curious what the difference is.

It's just the usual argument about whether 'log' means
log base 10 or log base e (natural log).  At least in the
US, most[*] calculus texts (and also most calculators),
for reasons best known to themselves, use 'ln' to mean
natural log and 'log' to mean log base 10.  But most
mathematicians use 'log' to mean natural log:  pick up a
random pure mathematics research paper that has the word
'log' in it, and unless it's otherwise qualified, it's
safe to assume that it means log base e.  (Except in the
context of algorithmic complexity, where it might well
mean log base 2 instead...)

Python also suffers a bit from this confusion:  the
Decimal class defines methods 'ln' and 'log10', while
the math module and cmath modules define 'log' and
'log10'.  (But the Decimal module has other problems,
like claiming that 0**0 is undefined while
infinity**0 is 1.)

[*] A notable exception is Michael Spivak's 'Calculus', which also
happens to be the book I learnt calculus from many years ago.

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


Re: GNUstep and Python

2009-06-23 Thread Eric Brunel
Diez B. Roggisch wrote:
> Paul Watson schrieb:
>> Has anyone used GNUstep?
>>
>> In addition to Objective-C, there are Java and Ruby bindings.
>>
>> Has anyone created a Python binding to GNUstep?
>
> There is the pyobjc-binding for OSX, maybe that's suitable for GNUStep.

Apparently, it's not: There was some compatibility in earlier versions, but
it's been officially removed in version 2.0. See
http://pyobjc.sourceforge.net/NEWS-2.0.html :
"GNUstep support has been removed because this has never worked properly,
nobody seems interested in fixing that and the internal APIs of PyObjC have
changed greatly."

I'd love to see that happen, but GNUStep seems to be disappearing little by
little. Too bad...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open source python projects

2009-06-23 Thread Michael Ströder
saurabh wrote:
> I am an experienced C programmer and recently dived into python,
> I have developed an instant love for it.
> I have been doing some routine scripting for day to day admin tasks,also 
> have done some Tkinter and socket programming using python.
> 
> I am looking for some open source python project preferably in one of
> the above areas (not strictly, am open to others too) to contribute.
> 
> Please give me any pointers to some python project which needs a 
> contributor.

I'm sure there are many projects which could need a helping hand. But
instead of pointing you to a specific project I'd rather recommend that
you contribute to projects you're using for your own daily work. Why?
Because you simply know what's really needed if you deploy a software
yourself.

Ciao, Michael.

-- 
Michael Ströder
E-Mail: mich...@stroeder.com
http://www.stroeder.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: launch a .py file from a batch file

2009-06-23 Thread Paul Moore
2009/6/23 C M :
>> Assuming you're running on Windows XP, try the following line in your
>> batch file:
>> @start path\MyPythonApp.pyw
>>
>> That's of course after you rename your script to a pyw extension.  That's
>> associated with pythonw, which doesn't need a command window.
>
> Well, I renamed my script to have a .pyw extension, and then ran the line
> above.  Without quotes, it doesn't find it (because I have spaces in the
> path).
> With quotes it just opens a console and does nothing (does not launch the
> app).
>
> Any ideas?

Use

@start "" "path\MyPythonApp.pyw"

The first item in quotes is the window title. If you only include the
path (in quotes) it's taken as a title, which is why you need the
second set of quotes.

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


Re: Error in reg dll

2009-06-23 Thread Girish
Hi,

somehow I fixed the issue related to error code 0xc005. Now I am
getting a different error code while registering DLL.. it says:
"DllRegisrerServer in Dspacvce.dll Failed. Reyurn Code was:
0x80040201"

On Jun 20, 8:15 am, "Gabriel Genellina" 
wrote:
> En Tue, 16 Jun 2009 02:09:57 -0300,Girish escribió:
>
> > I am not able to registerDLLgenerated from py2exe
> > When I try to register thedllusing the commant: regsve32 dspace.dll,
> > I am getting error saying :"DLLRegisterServer in dspace.dllfailed.
> > Return code was: 0xc005"
>
> I don't think the problem is in your setup.py, but on Dspace.py or any  
> module it uses. 0xc005 is an Access Violation - an attempt to  
> read/write memory at an illegal address.
> Try removing pieces from Dspace.py until you find the culprit.
>
> --
> Gabriel Genellina

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


How to find info about python 3.x extension module availability?

2009-06-23 Thread Francesco Bochicchio
Hi all,

is there any site that reports the current porting (to Python 3.x)
status of the main non-standard extension modules (such as pygtk,
pywin32, wxpython, ...) ?
I think such information would be very useful for people - like me -
which are tryiing to decide how/when/if to port existing scripts/
applications to the new python, or also  which python to use to start
a new program.

I searched and googled for this information  but without finding
anything. It looks to me that also the single extension module sites
are quite shy at announcing plans for the porting (I understand that
in part this is for the "is ready when is ready" philosophy of many
non-large open software projects).

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


Re: Idioms and Anti-Idioms Question

2009-06-23 Thread Lawrence D'Oliveiro
In message , Peter Billam wrote:

> Damian Conway, in Perl Best Practices, puts forward a clear argument
> for breaking *before* the operator:

Except in JavaScript, where you have no choice.

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


Re: UnicodeDecodeError: problem when path contain folder start withcharacter 'u

2009-06-23 Thread aberry

thanks all for help...
actually this was in old code having 'unicode_escape' .
i hope it was there to handle path which may contain localized chars...

but removing unicode_escape' it worked fine... :)

rgds,
aberry


Mark Tolonen-3 wrote:
> 
> 
> "aberry"  wrote in message 
> news:24146775.p...@talk.nabble.com...
>>
>> I am facing an error on Unicode decoding of path if it contain a 
>> folder/file
>> name starting with character 'u' .
>>
>> Here is what I did in IDLE
>> 1. >>> fp = "C:\\ab\\anil"
>> 2. >>> unicode(fp, "unicode_escape")
>> 3. u'C:\x07b\x07nil'
>> 4. >>> fp = "C:\\ab\\unil"
>> 5. >>> unicode(fp, "unicode_escape")
>> 6.
>> 7. Traceback (most recent call last):
>> 8.   File "", line 1, in 
>> 9. unicode(fp, "unicode_escape")
>> 10. UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in 
>> position
>> 5-9: end of string in escape sequence
>> 11. >>>
>>
>> Not sure whether I am doing something wrong or this is as designed 
>> behavior
>> .
>> any help appreciated
> 
> What is your intent?  Below gives a unicode strings with backslashes.  No 
> need for unicode_escape here.
> 
 fp = "C:\\ab\\unil"
 fp
> 'C:\\ab\\unil'
 print fp
> C:\ab\unil
 unicode(fp)
> u'C:\\ab\\unil'
 print unicode(fp)
> C:\ab\unil
 u'C:\\ab\\unil'
> u'C:\\ab\\unil'
 print u'C:\\ab\\unil'
> C:\ab\unil
> 
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

-- 
View this message in context: 
http://www.nabble.com/UnicodeDecodeError%3A-problem-when-path-contain-folder-start-with-character-%27u-tp24146775p24164207.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


I look for private Python Index server on my local network... What do you use ?

2009-06-23 Thread Klein Stéphane
Hi,

I wonder what Python Index server (like as pypi.python.org) do you use in 
your corporation for handle your private python eggs ?

I found three solutions :

* http://pypi.python.org/pypi/basketweaver/0.1.2-r6
* http://pypi.python.org/pypi/pypi/2005-08-01
* http://pypi.python.org/pypi/EggBasket/0.6.1b

Do you know another software ? What do you use ?

Thanks for your help,
Stephane

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


Authenticating to web service using https and client certificate

2009-06-23 Thread jakecjacobson
Hi,

I need to post some XML files to a web client that requires a client
certificate to authenticate.  I have some code that works on posting a
multipart form over http but I need to modify it to pass the proper
certificate and post the XML file.  Is there any example code that
will point me in the correct direction?  Thanks for your help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: launch a .py file from a batch file

2009-06-23 Thread Dave Angel

Paul Moore wrote:

2009/6/23 C M :
  

Assuming you're running on Windows XP, try the following line in your
batch file:
@start path\MyPythonApp.pyw

That's of course after you rename your script to a pyw extension.  That's
associated with pythonw, which doesn't need a command window.
  

Well, I renamed my script to have a .pyw extension, and then ran the line
above.  Without quotes, it doesn't find it (because I have spaces in the
path).
With quotes it just opens a console and does nothing (does not launch the
app).

Any ideas?



Use

@start "" "path\MyPythonApp.pyw"

The first item in quotes is the window title. If you only include the
path (in quotes) it's taken as a title, which is why you need the
second set of quotes.

Paul.

  
CM - Paul is right.  If you have to use quotes, then you also need the 
extra argument to hold the "title" for the command window that won't be 
created.  Stupid syntax on "Start.exe".  I seldom hit that because I try 
not to put anything in a directory with spaces in it, like   "Program 
Files" or "Documents and Settings"


I have uncovered dozens of bugs in other people's programs over the 
years that were triggered by spaces in the pathname.  It's not so bad 
now, but still can bite you.



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


C-extension 2 times slower than exe

2009-06-23 Thread Rolf Wester
Hi,

I have a C++ program that I would like to steer using Python. I made the
wrapper using swig and linked the code (without the main function) into
a shared object. My Python script loads the extension and calls a
function of the C-extension, the rest runs entirely within the
C-extension. For comparison I compiled the code including the main
function with the same compilation options and linked all into an exe.
The main function of the exe calls the same function as my Python script
does. Surprisingly the code in the Python C-extension runs twice as long
as the same code in the exe. Does anyone know what could be the reason
for this behaviour?

Thank you in advance

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


Re: C-extension 2 times slower than exe

2009-06-23 Thread Philip Semanchuk


On Jun 23, 2009, at 9:51 AM, Rolf Wester wrote:


Hi,

I have a C++ program that I would like to steer using Python. I made  
the
wrapper using swig and linked the code (without the main function)  
into

a shared object. My Python script loads the extension and calls a
function of the C-extension, the rest runs entirely within the
C-extension. For comparison I compiled the code including the main
function with the same compilation options and linked all into an exe.
The main function of the exe calls the same function as my Python  
script
does. Surprisingly the code in the Python C-extension runs twice as  
long

as the same code in the exe. Does anyone know what could be the reason
for this behaviour?


If the runtime of the C/C++ code is short, the time spent initializing  
the Python interpreter might have a big impact on the runtime of the  
Python version.



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


Re: C-extension 2 times slower than exe

2009-06-23 Thread Rolf Wester
Philip Semanchuk wrote:
> 
> On Jun 23, 2009, at 9:51 AM, Rolf Wester wrote:
> 
>> Hi,
>>
>> I have a C++ program that I would like to steer using Python. I made the
>> wrapper using swig and linked the code (without the main function) into
>> a shared object. My Python script loads the extension and calls a
>> function of the C-extension, the rest runs entirely within the
>> C-extension. For comparison I compiled the code including the main
>> function with the same compilation options and linked all into an exe.
>> The main function of the exe calls the same function as my Python script
>> does. Surprisingly the code in the Python C-extension runs twice as long
>> as the same code in the exe. Does anyone know what could be the reason
>> for this behaviour?
> 
> If the runtime of the C/C++ code is short, the time spent initializing
> the Python interpreter might have a big impact on the runtime of the
> Python version.
> 
> 
The runtime is about 2.5 sec and 5.0 sec respectively. I not only use
the time command to measure the time consumed but I also measure the
time within the C-code using clock() and get similar result. So the
Python startup time is not the reason for the runtime difference I
found. Thank you anyway.

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


Re: UnicodeDecodeError: problem when path contain folder startwithcharacter 'u

2009-06-23 Thread Mark Tolonen


"aberry"  wrote in message 
news:24164207.p...@talk.nabble.com...

Mark Tolonen-3 wrote:

"aberry"  wrote in message
news:24146775.p...@talk.nabble.com...


I am facing an error on Unicode decoding of path if it contain a
folder/file
name starting with character 'u' .

Here is what I did in IDLE
1. >>> fp = "C:\\ab\\anil"
2. >>> unicode(fp, "unicode_escape")
3. u'C:\x07b\x07nil'
4. >>> fp = "C:\\ab\\unil"
5. >>> unicode(fp, "unicode_escape")
6.
7. Traceback (most recent call last):
8.   File "", line 1, in 
9. unicode(fp, "unicode_escape")
10. UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in
position
5-9: end of string in escape sequence
11. >>>

Not sure whether I am doing something wrong or this is as designed
behavior
.
any help appreciated


What is your intent?  Below gives a unicode strings with backslashes.  No
need for unicode_escape here.


fp = "C:\\ab\\unil"
fp

'C:\\ab\\unil'

print fp

C:\ab\unil

unicode(fp)

u'C:\\ab\\unil'

print unicode(fp)

C:\ab\unil

u'C:\\ab\\unil'

u'C:\\ab\\unil'

print u'C:\\ab\\unil'

C:\ab\unil


thanks all for help...
actually this was in old code having 'unicode_escape' .
i hope it was there to handle path which may contain localized chars...

but removing unicode_escape' it worked fine... :)


If that was the case, then here's a few other options:


print 'c:abcunil\\xe4'.decode('unicode_escape')

c:\abc\unilä

print r'c:\\abc\\unil\xe4'.decode('unicode_escape')

c:\abc\unilä

print u'c:\\abc\u005cunil\u00e4'

c:\abc\unilä

print ur'c:\abc\u005cunil\u00e4'

c:\abc\unilä

You can also use forward slashes as another poster mentioned.  If you want 
to display the filenames with the backslashes, os.path.normpath can be used:



print os.path.normpath('c:/abc/unil\u00e4'.decode('unicode_escape'))

c:\abc\unilä

Note you only have to jump through these hoops to generate hard-coded 
filenames with special characters.  If they are already on disk, just read 
them in with something like os.listdir(u'.'), which generates a list of 
unicode filenames.


-Mark


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


Re: walking a directory with very many files

2009-06-23 Thread Mel
Steven D'Aprano wrote:

> Lawrence D'Oliveiro wrote:
> 
>>> Ok, now pipe ls to less, take three days to browse through all the
>>> filenames to locate the file you want to see.
>> 
>> Sounds like you're approaching the issue with a GUI-centric mentality,
>> which is completely hopeless at dealing with this sort of situation.
> 
> Piping the output of ls to less is a GUI-centric mentality?

Yeah.  The "dump it on the user" idea, or more politely "can't decide 
anything until the user has seen everything" is evident in the most 
"characteristic" GUIs.

Mel.


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


Re: I look for private Python Index server on my local network... What do you use ?

2009-06-23 Thread Jeff McNeil
On Jun 23, 7:47 am, Klein Stéphane  wrote:
> Hi,
>
> I wonder what Python Index server (like as pypi.python.org) do you use in
> your corporation for handle your private python eggs ?
>
> I found three solutions :
>
> *http://pypi.python.org/pypi/basketweaver/0.1.2-r6
> *http://pypi.python.org/pypi/pypi/2005-08-01
> *http://pypi.python.org/pypi/EggBasket/0.6.1b
>
> Do you know another software ? What do you use ?
>
> Thanks for your help,
> Stephane

I've always just created a directory structure laid out by egg name
and enabled directory indexing. I've never really had a need for
anything more complex and this has always worked well for me.

For example:

[r...@buildslave01 eggs]# pwd
/var/www/html/eggs
[r...@buildslave01 eggs]#

[r...@buildslave01 eggs]# ls
Beaker   hostapi.logmgmt   PasteSQLAlchemy
zope.component
[r...@buildslave01 eggs]#

[r...@buildslave01 eggs]# ls Beaker/
Beaker-1.1.2-py2.4.egg  Beaker-1.2.1-py2.4.egg
[r...@buildslave01 eggs]#

On this particular system, buildbot drops successfully built eggs into
the correct location automatically for testing purposes.

HTH,

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


Re: How to find info about python 3.x extension module availability?

2009-06-23 Thread Francesco Bochicchio
On 23 Giu, 12:59, Francesco Bochicchio  wrote:
> Hi all,
>
> is there any site that reports the current porting (to Python 3.x)
> status of the main non-standard extension modules (such as pygtk,
> pywin32, wxpython, ...) ?
> I think such information would be very useful for people - like me -
> which are tryiing to decide how/when/if to port existing scripts/
> applications to the new python, or also  which python to use to start
> a new program.
>
> I searched and googled for this information  but without finding
> anything. It looks to me that also the single extension module sites
> are quite shy at announcing plans for the porting (I understand that
> in part this is for the "is ready when is ready" philosophy of many
> non-large open software projects).
>
> Ciao
> -
> FB


Well, I kept searching and found this at least :

http://www.daniweb.com/forums/thread165340.html

It lists Qt , BeautfulSoup (with problems) and pywin32 (which I use a
lot :-)
Another (less famous) module that I use, ply, also supports python3.x

Maybe in the near future I can start porting some of my scripts ...

Still believe that a central point to keep track of most of extension
porting effort would be very useful ...


Ciao

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


Help with dictionaries and multidimensial lists

2009-06-23 Thread Cameron Pulsford
Hey all, I have a dictionary that looks like this (small example version)
{(1, 2): 0} named a

so I can do a[1,2] which returns 0. What I also have is a list of
coordinates into a 2 dimensional array that might look like this b =
[[1,2]]. Is there anyway I can call a[b[0]] and have it return 0?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Mac] file copy

2009-06-23 Thread Diez B. Roggisch
Tobias Weber wrote:

> Hi,
> which is the best way to copy files on OS X? I want to preserve resource
> forks and extended attributes.

Are these still relevant on OSX? I've always only copied files directly, and
never had any troubles.

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


Re: Procedures

2009-06-23 Thread J. Cliff Dyer
Please keep the discussion on-list. (Reply-all, rather than just
replying to me.) 

On Mon, 2009-06-22 at 15:36 -0700, Greg Reyna wrote:
> It's not the error that concerned me.  The fact that there is an 
> error of this type makes clear that there's something wrong with the 
> way the scripts are structured.  I was trying to communicate that I 
> recognized this fact.  Clearly, I was not successful.  Thought I'd 
> try to save bandwidth, too.
> ...
> I had tried running this previously with only one Class header: 
> "LineReader", the others were just defs.  I changed the short defs 
> into sub-classes out of desperation, since I don't understand why the 
> main script is not recognizing functions that are in the same file.
> 
> First is the shell input/output, then "ParseWork.py", the entire text 
> file that contains the scripts.
> 
> Thanks for your interest, Cliff,
> Greg
> ---
> >>>  import ParseWork
> >>>  avar = ParseWork.LineReader()
> >>>  xstring = 'scene 1, pnl 1, 3+8, pnl 2, 1+12, pnl 3, 12, pnl 4, 2+4,'
> >>>  avar.parseLine(xstring)
> Traceback (most recent call last):
>File "", line 1, in 
>File "ParseWork.py", line 13, in parseLine
>  xreturn = advanceSearch(xstring)  #shorten the part of string to 
> be searched
> NameError: global name 'advanceSearch' is not defined
> >>>
> ---
> class LineReader:   
>  def parseLine(self, xstring):
>  global sc_info,scnum,pnlnum,prev_pos,cur_pos
>  sc_info = { 'sc':{0:0}}  #dict to store scene num; pnl num(s), ftge
>  prev_pos = 0
>  cur_pos = xstring.find(',') #defaults to length of string
>  while xstring.find(',',(prev_pos+1))  !=  -1: 
>  temp = xstring[prev_pos:cur_pos]   #pull out the part btwn commas
>  section = temp.strip()   
>  if section[0:1] == 's':
>  scnum = int(section[5:])  #get the number(s) off the 
> end of scene block
>  sc_info['sc',scnum] = scnum  #store scnum-which is 
> both key and value
>  xreturn = advanceSearch(xstring)  #shorten the part 
> of string to be searched
>  continue
>  if section[0:1] == 'p':
>  pnlnum = int(section[3:])
>  sc_info['sc',scnum,pnlnum] = pnlnum  #store pnlnum & 
> temp value for pnlnum
>  xreturn = advanceSearch(xstring)  #the return value 
> is to move flow back here
>  continue
>  if section[0:1] != 's' or 'p':
>  xnum = section[0:]   #section must contain the footage
>  if section.find('+'):   #the + exists
>  ftge = parseFtge(section) 
>  sc_info['sc',scnum,pnlnum] = ftge  #store ftge in pnlnum
>  xreturn = advanceSearch(xstring)
>  continue
>  else:
>  ftge = (section/16.0)  #section is frames-convert 
> to decimal
>  sc_info['sc',scnum,pnlnum] = ftge  #store ftge in pnlnum
>  xreturn = advanceSearch(xstring)
>  continue
>  else:
>  print sc_info
> 
> class ContRead(LineReader):   
>  def advanceSearch(xstring):
>  prev_pos = (cur_pos +1) 
>  cur_pos = xstring.find(',',prev_pos)  #find the next comma  
>  return
> 
> class Footage(LineReader):   
>  def parseFtge(section):
>  xplus = section.find('+')  #find position of '+'
>  xfeet = int(section[0:xplus])
>  xframes = int(section[(xplus + 1):-1])  
>  xframes_d = (xframes/16.0)
>  return (xfeet + xframes_d)
> 
> 


>From what I can see you have no need for classes in your code.  This is
probably what is causing you trouble at the moment, so I would say just
remove them.  

def parse_line(line):
"""splits a line on commas"""
return line.split(',')

def parse_footer(line):
"""Strips off leading four characters (maybe 'Ftr:'), and then
parses the rest as above"""
return parse_line([4:])

That should solve your problem.  Below I illustrate some of how classes
work, in case you are dead set on using them.  Learning Python should
address all of this as well.  I haven't read it, so I can't be more
specific.

To call a method from another method within a class, you need to prefix
it with self.  That looks like this:

class Spam(object):  ## {1}
def parse_line(self, line):  ## {2}
return line.split(',')

def parse_footer(self, line):
return self.parse_line(line[4:])  ## {3}

# {1} always subclass 'object' to use newstyle classes
# {2} Note that method declarations have an extra first argument, 
# usually called "self", which refers to your instance of the class.
# {3} "self" finds parse_line within the current class
# or superclasses of the current class.  Note that self has 
# moved from inside the parentheses to before the method 

Re: [Mac] file copy

2009-06-23 Thread Philip Semanchuk


On Jun 23, 2009, at 10:54 AM, Diez B. Roggisch wrote:


Tobias Weber wrote:


Hi,
which is the best way to copy files on OS X? I want to preserve  
resource

forks and extended attributes.


Are these still relevant on OSX? I've always only copied files  
directly, and

never had any troubles.


I think resource forks are now stored as extended attributes, and  
Apple's version of cp is aware of extended attributes.


Try this -- create a text file via terminal using `touch foo.txt`. In  
Finder, click "get info" on the file and change it to open with  
anything other than TextEdit (e.g. Firefox).


Now go back to terminal and look at the file. It's still zero bytes  
long, but try the command `xattr foo.txt` --


$ xattr foo.txt
com.apple.FinderInfo
com.apple.ResourceFork

Also --
$ cp foo.txt bar.txt
$ xattr bar.txt
com.apple.FinderInfo
com.apple.ResourceFork

xattr -h gives options for this command.

To the OP -- I remember reading somewhere that xattr is written in  
Python. You might find it useful or even be able to import it directly.



HTH
Philip




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


Re: How to find info about python 3.x extension module availability?

2009-06-23 Thread Jeff McNeil
On Jun 23, 6:59 am, Francesco Bochicchio  wrote:
> Hi all,
>
> is there any site that reports the current porting (to Python 3.x)
> status of the main non-standard extension modules (such as pygtk,
> pywin32, wxpython, ...) ?
> I think such information would be very useful for people - like me -
> which are tryiing to decide how/when/if to port existing scripts/
> applications to the new python, or also  which python to use to start
> a new program.
>
> I searched and googled for this information  but without finding
> anything. It looks to me that also the single extension module sites
> are quite shy at announcing plans for the porting (I understand that
> in part this is for the "is ready when is ready" philosophy of many
> non-large open software projects).
>
> Ciao
> -
> FB

You can pull a list of what works with 3.0 via PyPi, there's a link
which points you to http://pypi.python.org/pypi?:action=browse&c=533&show=all.
If the package isn't listed on PyPi, I believe you'll have to check
out the vendor/distribution site.

I posted something like this on my blog a few months back.  Finding
what's available isn't too terribly difficult. I thought it would be
nice to have a port status page that lets the community know where
certain package stand so volunteers can step in and help. I guess it
would be rather difficult to keep such a page updated, though.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Idioms and Anti-Idioms Question

2009-06-23 Thread Gabriel Genellina
En Mon, 22 Jun 2009 20:34:40 -0300, Miles Kaufmann   
escribió:

On Jun 22, 2009, at 12:14 AM, Ben Charrow wrote:

What is subtly wrong about this piece of code?  I can't see any bugs  
and can't think of subtle gotchas (e.g. the '\' is removed or the lines  
become separated, because in both cases an IndentationError would be  
raised).


Perhaps, along with one of those gotchas, a mix of tabs and spaces are  
used such that the second line only _appears_ to have a different level  
of indentation? ;)


Neither. As back in time as I can go (Python 1.5), having any character  
after the backslash has always been a syntax error no matter what. Only  
the error message has changed:


C:\TEMP>python15 syntaxerror.py
  File "syntaxerror.py", line 18
value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \
   ^
SyntaxError: invalid token

So the "it might be subtly wrong" argument is strongly wrong.

--
Gabriel Genellina

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


Re: Help with dictionaries and multidimensial lists

2009-06-23 Thread Jaime Fernandez del Rio
On Tue, Jun 23, 2009 at 4:45 PM, Cameron
Pulsford wrote:
> Hey all, I have a dictionary that looks like this (small example version)
> {(1, 2): 0} named a
>
> so I can do a[1,2] which returns 0. What I also have is a list of
> coordinates into a 2 dimensional array that might look like this b =
> [[1,2]]. Is there anyway I can call a[b[0]] and have it return 0?

a[tuple(b[0])] should do it...

Jaime

-- 
(\__/)
( O.o)
( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus
planes de dominación mundial.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Idioms and Anti-Idioms Question

2009-06-23 Thread Carl Banks
On Jun 21, 9:14 pm, Ben Charrow  wrote:
> I have a question about the "Using Backslash to Continue Statements" in the
> howto "Idioms and Anti-Idioms in Python"
> (http://docs.python.org/howto/doanddont.html#using-backslash-to-contin...)
>
> It says:
>
> "...if the code was:
>
> value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \
>          + calculate_number(10, 20)*forbulate(500, 360)
>
> then it would just be subtly wrong."
>
> What is subtly wrong about this piece of code?  I can't see any bugs and can't
> think of subtle gotchas (e.g. the '\' is removed or the lines become 
> separated,
> because in both cases an IndentationError would be raised).

Perhaps it was originally was like this:

value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \
+ calculate_number(10, 20)*forbulate(500, 360)


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


Re: Help with dictionaries and multidimensial lists

2009-06-23 Thread Cameron Pulsford
Thanks!

On Tue, Jun 23, 2009 at 11:29 AM, Jaime Fernandez del Rio <
jaime.f...@gmail.com> wrote:

> On Tue, Jun 23, 2009 at 4:45 PM, Cameron
> Pulsford wrote:
> > Hey all, I have a dictionary that looks like this (small example version)
> > {(1, 2): 0} named a
> >
> > so I can do a[1,2] which returns 0. What I also have is a list of
> > coordinates into a 2 dimensional array that might look like this b =
> > [[1,2]]. Is there anyway I can call a[b[0]] and have it return 0?
>
> a[tuple(b[0])] should do it...
>
> Jaime
>
> --
> (\__/)
> ( O.o)
> ( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus
> planes de dominación mundial.
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting Python code to C/C++

2009-06-23 Thread Kurt Smith
On Mon, Jun 22, 2009 at 9:49 PM, Andras
Pikler wrote:
> Hi!
>
>
>
> Short: I need to turn a Python program that I (mostly) wrote into C code,
> and I am at a loss.
>
>
>
> Long: I’m doing research/programming for a professor, and we are working
> with MIDI files (a type of simple music file). The research deals with
> generating variations from a musical melody; currently, my Python code uses
> a Python midi package I found online to read the notes in question from a
> midi file, about 350 lines of my own code to generate a variation based on
> these notes and the professor’s algorithms, and finally the package again to
> write the new melody to another midi file.
>
>
>
> Now, my professor would like to have this exact code in C/C++, as she
> believes C is more compatible with MATLAB, and wants the code to be
> available in multiple languages in case a programmer works for her in the
> future who knows C but not Python. While I know a tiny bit of C (emphasis on
> the tiny), I would much prefer if there were some sort of automatic compiler
> I could use to turn my Python code into C than taking a week or two or three
> to learn the minimum I need about C, find a way to access MIDI files in it,
> and rewrite all of my code.
>
>
>
> After some googling, I found and tried Shedskin, but it doesn’t work, as the
> Python midi package I’m using uses modules which Shedskin does not support.
> Otherwise, I haven’t found much. Is there anything out there to help me do
> this? If not, from anyone who has experience in this regard, how daunting
> should I expect this to be?


Taking on C from a cold start and being able to handle the ins and
outs of interfacing with Python isn't something that's feasible in
'two or three weeks'.  Here are a couple of options -- take 'em or
leave 'em:

1) Put the code in Cython: http://www.cython.org/  (full disclosure:
I'm doing a GSoC project with Cython).  It will convert pretty much
any python code into C code (even closures are supported in the most
recent version, I think), and the C code can then be compiled into an
extension module.

The only problem with the above is the C code isn't, at first blush,
easy to read.  Nor is it supposed to be changed by the user.  So that
leads us to option...

2) Write the core functionality in C yourself, and then wrap those C
functions in Cython.  You'll want to take a look at the documentation:

http://docs.cython.org/

and, more specifically on wrapping C code:

http://docs.cython.org/docs/external_C_code.html

I don't think you'll be able to avoid learning C, though.

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


Re: Idioms and Anti-Idioms Question

2009-06-23 Thread J. Cliff Dyer
On Mon, 2009-06-22 at 22:52 +, Peter Billam wrote:

> I wonder on what grounds PEP8
> says "The preferred place to break around a binary operator is
> *after* the operator" ?
> Perhaps it's just the "continutation marker" rationale?
> 
> Regards,  Peter
> 
> -- 
> Peter Billam   www.pjb.com.auwww.pjb.com.au/comp/contact.html


If the lines got separated, a leading + could disappear into its line
without any errors showing up.  A trailing + would raise a syntax error.

>>> spam = 6
>>> spam +
  File "", line 1
spam +
 ^
SyntaxError: invalid syntax
>>> + spam
6
>>> 



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


help!

2009-06-23 Thread tanner barnes

Python Version: 2.6
GUI toolkit: WxPython

Ok so i am writing a program for my school's football team. In one part there 
is a notebook with 4 tabs for that stats. In each 
tab there are 4 txtctrl's with a + and - for each. The problem im having is 
that i need when you click the + or - button that it updates that stat for the 
player. 

_
Microsoft brings you a new way to search the web.  Try  Bing™ now
http://www.bing.com?form=MFEHPG&publ=WLHMTAG&crea=TEXT_MFEHPG_Core_tagline_try_bing_1x1-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to find info about python 3.x extension module availability?

2009-06-23 Thread Francesco Bochicchio
On 23 Giu, 17:12, Jeff McNeil  wrote:
> On Jun 23, 6:59 am, Francesco Bochicchio  wrote:
>
>
>
>
>
> > Hi all,
>
> > is there any site that reports the current porting (to Python 3.x)
> > status of the main non-standard extension modules (such as pygtk,
> > pywin32, wxpython, ...) ?
>
> You can pull a list of what works with 3.0 via PyPi, there's a link
> which points you tohttp://pypi.python.org/pypi?:action=browse&c=533&show=all.
> If the package isn't listed on PyPi, I believe you'll have to check
> out the vendor/distribution site.
>
> I posted something like this on my blog a few months back.  Finding
> what's available isn't too terribly difficult. I thought it would be
> nice to have a port status page that lets the community know where
> certain package stand so volunteers can step in and help. I guess it
> would be rather difficult to keep such a page updated, though
>
> - Mostra testo citato -

Thanks.

I thought of pypy, and even tried to search for Python 3 using its
search button, but somehow missed the
handy "python 3" link on the sidebar :-0

I agree that keeping a complete list would be very difficult, although
useful ...

Ciao

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


Re: [Mac] file copy

2009-06-23 Thread Philip Semanchuk


On Jun 23, 2009, at 12:20 PM, Tobias Weber wrote:


In article ,
Philip Semanchuk  wrote:


I think resource forks are now stored as extended attributes, and


No


I'll take your word for it because I was just guessing, but then why  
do the xattrs in the example I gave show a resource fork?






Apple's version of cp is aware of extended attributes.


Yes, but the manual doesn't say to what extent, nor anything about  
ACLs


Your original question didn't say anything about ACLs either.



To the OP -- I remember reading somewhere that xattr is written in
Python. You might find it useful or even be able to import it  
directly.


It uses a C extension, but I could import it if I wanted to re-invent
the wheel ;)



Isn't importing a module that's already written the exact opposite of  
re-inventing the wheel?







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


Re: reply to OT diversion (was: What is the best method to match a pattern in set of lines

2009-06-23 Thread Aahz
In article <024d7a38$0$20654$c3e8...@news.astraweb.com>,
Steven D'Aprano   wrote:
>Dennis Lee Bieber wrote:
>> On Sat, 20 Jun 2009 13:47:24 -0700 (PDT), Bearophile
>>  declaimed the following in
>> gmane.comp.python.general:
>>> 
>>> Dennis Lee Bieber, may I ask why most or all your posts are set to "No-
>>> Archive"?
>> 
>> I'm from the days when the majority of NNTP servers were configured
>> to expire posts after some number of days (Netcom used to expire binary
>> groups after 24 hours! and most others were something like 14 days).
>> 
>> Then came the precursor to GoogleGroups -- DejaNews -- threatening
>> to archive posts through eternity. This resulted in a fair amount of
>> protesting by some, and the creation of the x-no-archive header
>> convention (Agent even has configuration options such that, if one were
>> to not normally use x-no-archive such that one's own posts could be
>> archived, one could still honor it in replies to posts that did contain
>> it -- so those replies with quoted contents would also not be archived).
>> 
>> It was at that time that I added the x-no-archive header to my posts
>> from Agent; as, while not as vocal as others, did object to DejaNews
>> plans.
>
>But your replies often contain useful information. It's a shame that they
>disappear from record, making them invisible for anyone searching the
>archives.
>
>A good rule of thumb when judging behaviour is to ask, "What if everyone did
>this?". If everyone set x-no-archive, then discussions on Usenet would be
>ephemeral, we couldn't point people to past discussions for information,
>and we would lose a lot of useful information. (Also a lot of garbage.) I
>can't tell you how often I find useful information in the archives of
>comp.lang.python thanks to those who archive the gname news-to-email
>gateway, and Google groups. If everyone did what you use, the entire
>community, including myself, would be far worse off.
>
>As far as I'm concerned, setting x-no-archive is harmful, anti-social
>behaviour on a technical newsgroup like this. You (almost) might as well
>just email the poster you're replying to directly.

Your response to Dennis seems at least a little over-the-top.  So far as
I'm concerned, anyone who joined Usenet after DejaNews is a latecomer;
trying to change the cultural beliefs of those who were here first is
asserting your superiority.  I happen to disagree with people who post
with X-no-archive, but I think it's certainly their right.

Guess what?  Prior to DejaNews, discussions on Usenet *were* ephemeral,
and it all worked.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open source python projects

2009-06-23 Thread Aahz
In article <4a3fde13$0$48239$14726...@news.sunsite.dk>,
saurabh   wrote:
>
>I am an experienced C programmer and recently dived into python,
>I have developed an instant love for it.
>I have been doing some routine scripting for day to day admin tasks,also 
>have done some Tkinter and socket programming using python.
>
>I am looking for some open source python project preferably in one of
>the above areas (not strictly, am open to others too) to contribute.

http://wiki.python.org/moin/VolunteerOpportunities
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Dynamic method invocation

2009-06-23 Thread jythonuser
Hi
I am new to jythong and was wondering if/how I can do the following -

a) register a java object with a given name with jython interpreter
using set method
b) call methods on the java object - but the methods may not exist on
the object, so I would like to call from jython a generic method that
I have defined on the object as opposed to using java reflection.
Thus the java class is more like a proxy for invocation.

As an example, I register an instance of java class Bar with name
foo.  I want to be able to call from jython -
foo.method1 (args)
I don't want to define all the methods that I can call from jython on
class foo but have a generic method that the above jython code will
invoke.  I want to use a model where the methods that can be called on
foo are discovered dynamically once they are invoked on java class.
Clearly Java won't let me do this during method invocation so I am
wondering if I can register some sort of proxy object with jython that
will let me then delegate right call down to the java object.

Thanks a bunch

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


Re: reply to OT diversion

2009-06-23 Thread MRAB

Aahz wrote:
[snip]

Your response to Dennis seems at least a little over-the-top.  So far as
I'm concerned, anyone who joined Usenet after DejaNews is a latecomer;
trying to change the cultural beliefs of those who were here first is
asserting your superiority.  I happen to disagree with people who post
with X-no-archive, but I think it's certainly their right.

Guess what?  Prior to DejaNews, discussions on Usenet *were* ephemeral,
and it all worked.


Difficult to prove, though, because the evidence no longer exists! :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Measuring Fractal Dimension ?

2009-06-23 Thread Lie Ryan
Mark Dickinson wrote:
> On Jun 23, 3:52 am, Steven D'Aprano
>  wrote:
>> On Mon, 22 Jun 2009 13:43:19 -0500, David C. Ullrich wrote:
>>> In my universe the standard definition of "log" is different froim what
>>> log means in a calculus class
>> Now I'm curious what the difference is.
> 
> It's just the usual argument about whether 'log' means
> log base 10 or log base e (natural log).  At least in the
> US, most[*] calculus texts (and also most calculators),
> for reasons best known to themselves, use 'ln' to mean
> natural log and 'log' to mean log base 10.  But most
> mathematicians use 'log' to mean natural log:  pick up a
> random pure mathematics research paper that has the word
> 'log' in it, and unless it's otherwise qualified, it's
> safe to assume that it means log base e.  (Except in the
> context of algorithmic complexity, where it might well
> mean log base 2 instead...)

I usually use log without explicit base only when the base isn't
relevant in the context (i.e. when whatever sane base you put in it
wouldn't really affect the operations). In algorithmic complexity, a
logarithm's base doesn't affect the growth shape and, like constant
multiplier, is considered irrelevant to the complexity.

> Python also suffers a bit from this confusion:  the
> Decimal class defines methods 'ln' and 'log10', while
> the math module and cmath modules define 'log' and
> 'log10'.  

In fact, in the Decimal class there is no log to an arbitrary base.

> (But the Decimal module has other problems,
> like claiming that 0**0 is undefined while
> infinity**0 is 1.)

Well, in math inf**0 is undefined. Since python is programming language,
and in language standards it is well accepted that undefined behavior
means implementations can do anything they like including returning 0,
1, 42, or even spitting errors, that doesn't make python non-conforming
implementation.

A more serious argument: in IEEE 745 float, inf**0 is 1. Mathematic
operation in python is mostly a wrapper for the underlying C library's
sense of math.

> [*] A notable exception is Michael Spivak's 'Calculus', which also
> happens to be the book I learnt calculus from many years ago.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reading a large csv file

2009-06-23 Thread python
Mag,

If your source data is clean, it may also be faster for you to parse
your input files directly vs. use the CSV module which may(?) add some
overhead.

Check out the struct module and/or use the split() method of strings.

We do a lot of ETL processing with flat files and on a slow single core
processing workstation, we can typically process 2 Gb of data in ~5
minutes. I would think a worst case processing time would be less than
an hour for 14 Gb of data.

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


Re: Idioms and Anti-Idioms Question

2009-06-23 Thread Lie Ryan
Peter Billam wrote:
> On 2009-06-22, Lie Ryan  wrote:
>> Ben Charrow wrote:
>>> value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \
>>> + calculate_number(10, 20)*forbulate(500, 360)
>>> What is subtly wrong about this piece of code?  I can't see any bugs and
>>> can't think of subtle gotchas (e.g. the '\' is removed or the lines
>>> become separated, because in both cases an IndentationError would be
>>> raised).
>> The preferred style is to put the binary operators before the line-break
>> (i.e. the line break is after the operators):
>> value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] + \
>> calculate_number(10, 20)*forbulate(500, 360)
>> ...
>> The following is an extract from PEP 8:
>> The preferred way of wrapping long lines is by using Python's
>> implied line continuation inside parentheses, brackets and braces.
>> If necessary, you can add an extra pair of parentheses around an
>> expression, but sometimes using a backslash looks better.  Make sure to
>> indent the continued line appropriately.  The preferred place to break
>> around a binary operator is *after* the operator, not before it.
> 
> Damian Conway, in Perl Best Practices, puts forward a clear argument
> for breaking *before* the operator:
>   Using an expression at the end of a statement gets too long,
>   it's common practice to break that expression after an operator
>   and then continue the expression on the following line ...
>   The rationale is that the operator that remains at the end
>   of the line acts like a continutation marker, indicating that
>   the expression continues on the following line.
>   Using the operator as a continutation marker seems like
>   an excellent idea, but there's a serious problem with it:
>   people rarely look at the right edge of code.
>   Most of the semantic hints in a program - such as keywords -
>   appear on the left side of that code.  More importantly, the
>   structural cues for understanding code - for example, indenting, - 
>   are predominantly on the left as well ... This means that indenting
>   the continued lines of the expression actually gives a false
>   impression of the underlying structure, a misperception that
>   the eye must travel all the way to the right margin to correct.
> 
> which seems to me well-argued.  I wonder on what grounds PEP8
> says "The preferred place to break around a binary operator is
> *after* the operator" ?
> Perhaps it's just the "continutation marker" rationale?
> 
> Regards,  Peter
> 

When you're *scanning* the code, breaking the line before the operator
might be better since you can easily see that that a line is a
continuation from the previous line.

However, when it comes to *reading* the code, it's easy to miss that the
code continues to the next line, especially when you rely on
parentheses' implicit line continuation and don't use an explicit
line-continuation character (i.e. \).

So... IMHO when it comes to break before or after the operator, it
depends on whether you rely on parentheses or explicit line
continuation. If you use implicit continuation with parentheses, it's
better to break after operators; else if you use explicit continuation
with \, it's better to break before operators.

Since python prefers using parentheses' implicit line cont., it follows
that breaking after operator is the natural choice.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: launch a .py file from a batch file

2009-06-23 Thread Che M
On Jun 23, 5:30 am, Paul Moore  wrote:
> 2009/6/23 C M :
>
> >> Assuming you're running on Windows XP, try the following line in your
> >> batch file:
> >> @start path\MyPythonApp.pyw
>
> >> That's of course after you rename your script to a pyw extension.  That's
> >> associated with pythonw, which doesn't need a command window.
>
> > Well, I renamed my script to have a .pyw extension, and then ran the line
> > above.  Without quotes, it doesn't find it (because I have spaces in the
> > path).
> > With quotes it just opens a console and does nothing (does not launch the
> > app).
>
> > Any ideas?
>
> Use
>
> @start "" "path\MyPythonApp.pyw"
>
> The first item in quotes is the window title. If you only include the
> path (in quotes) it's taken as a title, which is why you need the
> second set of quotes.
>
> Paul.

Unfortunately, when I try that it says "Windows cannot find [that
file]", etc.
And yet I am copying the filename right from the file manager and it
IS
there.

What's also odd is that if I open the file using cd and then just
putting
the filename on the next line, that file (which I gave a .pyw
extension)
doesn't open, but a file that has a .py extension does.

Any ideas?
Thanks.
Che

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


Re: Perl's @foo[3,7,1,-1] ?

2009-06-23 Thread Lie Ryan
Jean-Michel Pichavant wrote:
> Lie Ryan wrote:
>> Jean-Michel Pichavant wrote:
>>
>> 
>>
>>  
>>> Maybe I've been a little bit too dictatorial when I was saying that
>>> renaming namespaces should be avoided.
>>> Sure your way of doing make sense. In fact they're 2 main purposes of
>>> having strong coding rules:
>>> 1/ ease the coder's life
>>> 2/ ease the reader's life
>>>
>>> The perfect rule satisfies both of them, but when I have to choose, I
>>> prefer number 2. Renaming packages, especially those who are world wide
>>> used, may confuse the reader and force him to browse into more code.
>>>
>>> From the OP example, I was just pointing the fact that **he alone**
>>> gains 3 characters when **all** the readers need to ask what means "np".
>>> Renaming namespaces with a well chosen name (meaningful) is harmless.
>>> 
>>
>> As long as you keep all import statements at the head of the file, there
>> is no readability problems with renaming namespace.
>>
>> Glance at the header file, see:
>> import numpy as np
>>
>> and it's not hard to mentally switch np as numpy...
>>
>> well, as long as your header doesn't look like this:
>> import numpy as np
>> import itertools as it
>> import Tkinter as Tk
>> from time import time as t
>>   
> 
> yep, your example is good, no namespace renaming ... :o)
> I would gladly accept the following renaming:
> import theMostEfficientPythonPackageInTheWorld as meppw
> Hopefully, package names are often usable as provided.
> 
> Moreover, writing numpy instead of np is not harder for the coder than
> switching mentally from np to numpy for the reader. It's just about who
> you want to make the life easier, the coder or the reader ?

My point was, use namespace renaming whenever that improves readability;
however like all tools, don't overuse it

Another usecase might be when you have two similarly named package which
might bring confusion on which is which if left as is.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Mac] file copy

2009-06-23 Thread Michael Torrie
Tobias Weber wrote:
>> Apple's version of cp is aware of extended attributes.
> 
> Yes, but the manual doesn't say to what extent, nor anything about ACLs

mv, cp, etc (but not rsync) are completely aware of resource forks from
Tiger on.  This is well documented and known on the Mac forums.

So shutils should work just fine for copying, moving, etc.

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


Re: C-extension 2 times slower than exe

2009-06-23 Thread Michael Torrie
Rolf Wester wrote:
> The runtime is about 2.5 sec and 5.0 sec respectively. I not only use
> the time command to measure the time consumed but I also measure the
> time within the C-code using clock() and get similar result. So the
> Python startup time is not the reason for the runtime difference I
> found. Thank you anyway.

Without a profiler it's hard to say where the time is being consumed.
You might want to use ctypes and open your c++ code as a DLL without the
python extension wrapper.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with dictionaries and multidimensial lists

2009-06-23 Thread Terry Reedy

Cameron Pulsford wrote:

Hey all, I have a dictionary that looks like this (small example version)

{(1, 2): 0} named a

so I can do a[1,2] which returns 0. What I also have is a list of 
coordinates into a 2 dimensional array that might look like this b = 
[[1,2]]. Is there anyway I can call a[b[0]] and have it return 0?


Unless you are mutating your coordinate pairs in place, which you very 
seldom would *have to* do, I would make them tuples.

b = [ (1,2), (3,5), ...]
This would even save a bit of memory.

I prefer this to converting list pairs to tuple pairs  on access.

tjr

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


Re: [Mac] file copy

2009-06-23 Thread Jerry Hill
On Tue, Jun 23, 2009 at 2:28 PM, Michael Torrie wrote:
> mv, cp, etc (but not rsync) are completely aware of resource forks from
> Tiger on.  This is well documented and known on the Mac forums.
>
> So shutils should work just fine for copying, moving, etc.

I don't think that's true.  The shutil docs
(http://docs.python.org/library/shutil.html) has a big red box at the
top that says:

"""
Warning

Even the higher-level file copying functions (copy(), copy2()) can’t
copy all file metadata.

On POSIX platforms, this means that file owner and group are lost as
well as ACLs. On Mac OS, the resource fork and other metadata are not
used. This means that resources will be lost and file type and creator
codes will not be correct. On Windows, file owners, ACLs and alternate
data streams are not copied.
"""

If I understand the OP's question from the first email in this thread,
that should pretty strongly warn you that shutil.copy2 is not going to
do what you want.  Not being a mac user myself, I don't know what the
right way to accomplish what you want is, though.

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


Re: Dynamic method invocation

2009-06-23 Thread Diez B. Roggisch

jythonuser schrieb:

Hi
I am new to jythong and was wondering if/how I can do the following -

a) register a java object with a given name with jython interpreter
using set method
b) call methods on the java object - but the methods may not exist on
the object, so I would like to call from jython a generic method that
I have defined on the object as opposed to using java reflection.
Thus the java class is more like a proxy for invocation.

As an example, I register an instance of java class Bar with name
foo.  I want to be able to call from jython -
foo.method1 (args)
I don't want to define all the methods that I can call from jython on
class foo but have a generic method that the above jython code will
invoke.  I want to use a model where the methods that can be called on
foo are discovered dynamically once they are invoked on java class.
Clearly Java won't let me do this during method invocation so I am
wondering if I can register some sort of proxy object with jython that
will let me then delegate right call down to the java object.


It's very unclear to me what you want, but to me, it looks as if you 
have some misconceptions about jython.


There is no "registration" of java-objects. If you have a java-object, 
you can assign it to a name, and simply invoke any method on it 
(internally, that will mean using reflection, but that's below the 
covers for you)


foo = SomeJavaClass()
foo.some_method()

As long as some_method is defined on SomeJavaClass, this will work. And 
there is also no type-information needed, so this will work in Jython, 
but not in java:



 java 

class A {
   public void foo() {};
}

class B { // NOT A SUBCLASS OF A!!
   public void foo() {};
}


 jython 

if some_condition:
   bar = A()
else:
   bar = B()

bar.foo()



Regarding the "generic method thing", I guess this will work:


foo = SomeJavaObject()

m = getattr(foo, "method_name_that_might_not_be_defined", None)

if m:
   m(argument)


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


Re: [Mac] file copy

2009-06-23 Thread Miles Kaufmann

On Jun 23, 2009, at 9:52 AM, Tobias Weber wrote:


Hi,
which is the best way to copy files on OS X? I want to preserve  
resource

forks and extended attributes.

...

bin/cp -p


This.  cp -p, mv, rsync -E, tar, and other utilities will use the  
copyfile(3) API to preserve extended attributes, resource forks, and  
ACLs.  cp -Rp should be just as safe as a Finder copy--moreso if you  
run it as root--with the exception of preserving creation dates.  Or  
if you're worried about hard links, check out ditto(1).


You presumably already know this, but avoid shutil at all costs.

BackupBouncer (http://www.n8gray.org/code/backup-bouncer/) makes  
testing what gets preserved by various methods of copying quick and  
easy.


The results for a Finder copy:

Verifying:basic-permissions ... FAIL (Critical)
Verifying:   timestamps ... ok (Critical)
Verifying: symlinks ... ok (Critical)
Verifying:symlink-ownership ... FAIL
Verifying:hardlinks ... FAIL (Important)
Verifying:   resource-forks ...
   Sub-test: on files ... ok (Critical)
   Sub-test:  on hardlinked files ... FAIL (Important)
Verifying: finder-flags ... ok (Critical)
Verifying: finder-locks ... ok
Verifying:creation-date ... ok
Verifying:bsd-flags ... ok
Verifying:   extended-attrs ...
   Sub-test: on files ... ok (Important)
   Sub-test:   on directories ... ok (Important)
   Sub-test:  on symlinks ... ok
Verifying: access-control-lists ...
   Sub-test: on files ... ok (Important)
   Sub-test:  on dirs ... ok (Important)
Verifying: fifo ... FAIL
Verifying:  devices ... FAIL
Verifying:  combo-tests ...
   Sub-test:  xattrs + rsrc forks ... ok
   Sub-test: lots of metadata ... FAIL

sudo cp -Rp:

Verifying:basic-permissions ... ok (Critical)
Verifying:   timestamps ... ok (Critical)
Verifying: symlinks ... ok (Critical)
Verifying:symlink-ownership ... ok
Verifying:hardlinks ... FAIL (Important)
Verifying:   resource-forks ...
   Sub-test: on files ... ok (Critical)
   Sub-test:  on hardlinked files ... FAIL (Important)
Verifying: finder-flags ... ok (Critical)
Verifying: finder-locks ... ok
Verifying:creation-date ... FAIL
Verifying:bsd-flags ... ok
Verifying:   extended-attrs ...
   Sub-test: on files ... ok (Important)
   Sub-test:   on directories ... ok (Important)
   Sub-test:  on symlinks ... ok
Verifying: access-control-lists ...
   Sub-test: on files ... ok (Important)
   Sub-test:  on dirs ... ok (Important)
Verifying: fifo ... ok
Verifying:  devices ... ok
Verifying:  combo-tests ...
   Sub-test:  xattrs + rsrc forks ... ok
   Sub-test: lots of metadata ... ok

-Miles

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


Re: help!

2009-06-23 Thread Benjamin Kaplan
On Tue, Jun 23, 2009 at 12:19 PM, tanner barnes wrote:
> Python Version: 2.6
> GUI toolkit: WxPython
>
> Ok so i am writing a program for my school's football team. In one part
> there is a notebook with 4 tabs for that stats. In each
> tab there are 4 txtctrl's with a + and - for each. The problem im having is
> that i need when you click the + or - button that it updates that stat for
> the player.
>

And what would you like us to tell you? Without specific details, the
only advice I can give is to bind an event to the plus and minus
buttons that updates the data. Or do you not know how to do that? What
do you mean by update? Update the text in the GUI, save to a text
file, or commit to a database? Please be as specific as possible.


> 
> Microsoft brings you a new way to search the web. Try Bing™ now
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Trouble with running java using Popen

2009-06-23 Thread Edward Grefenstette
I have a java prog I need to run at some point during the execution of
a python module.

The path to the folder containing the all the relevant java stuff
(which runs fine from the command line) is stored in pkgpath. The
relevant code is this:

>>> os.chdir(pkgpath)
>>> arglist = "java -Xmx1024m SemanticVectorsEvaluator ." + indexpath
>>> SemVectPackage = Popen(arglist, stdout=PIPE, shell=True)
>>> SemVectPackage.wait()

Here indexpath is the path to a particular index file (usually
indexpath = "./indexfolder/fileindex"), so that effectively Popen
should be running the equivalent of the shell command:
-
java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex
-
which, again, runs fine in the terminal.

However running the program returns the following error (echoed from
shell, doesn't interrupt prog):
-
Exception in thread "main" java.lang.NoClassDefFoundError:
SemanticVectorsEvaluator
-

I have no idea why this isn't working. Anyone have any suggestions as
to how I might troubleshoot this?

Best,
Edward
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: re.NONE

2009-06-23 Thread 1x7y2z9
On Jun 22, 5:56 pm, Lawrence D'Oliveiro  wrote:
> In message 
> c77d-4a47-8cb4-7dd916d69...@s1g2000prd.googlegroups.com>, 1x7y2z9 wrote:
> > Not sure if this is defined in a later version, but it would be nice
> > to define re.NONE = 0 in the re module.
>
> Do so:
>
>     re.NONE = 0
>
> Problem solved.

It would be nice to have such a constant defined in the re module
(make it standard).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: launch a .py file from a batch file

2009-06-23 Thread Dave Angel

Che M wrote:

On Jun 23, 5:30 am, Paul Moore  wrote:
  

2009/6/23 C M :



Assuming you're running on Windows XP, try the following line in your
batch file:
@start path\MyPythonApp.pyw

That's of course after you rename your script to a pyw extension.  That's

associated with pythonw, which doesn't need a command window.


Well, I renamed my script to have a .pyw extension, and then ran the line
above.  Without quotes, it doesn't find it (because I have spaces in the
path).
With quotes it just opens a console and does nothing (does not launch the
app).
  
Any ideas?
  

Use

@start "" "path\MyPythonApp.pyw"

The first item in quotes is the window title. If you only include the
path (in quotes) it's taken as a title, which is why you need the
second set of quotes.

Paul.



Unfortunately, when I try that it says "Windows cannot find [that
file]", etc.
And yet I am copying the filename right from the file manager and it
IS
there.

What's also odd is that if I open the file using cd and then just
putting
the filename on the next line, that file (which I gave a .pyw
extension)
doesn't open, but a file that has a .py extension does.

Any ideas?
Thanks.
Che


  
If you run the xx.pyw file interactively, does it work?  If not, perhaps 
the pyw file association is broken.  It, along with the py association, 
should have been set up by the Python install.


You can check it (and fix it) with
  assoc and ftype.   Here's what mine look like:

M:\>assoc .pyw
.pyw=Python.NoConFile

M:\>ftype Python.NoConFile
Python.NoConFile="C:\ProgFiles\Python26\pythonw.exe" "%1" %*


Or, as I said in an earlier message, you could explicitly specify the 
interpreter to be run on the start line.


Something like:
@start "notitle"  "c:\ProgFiles\Python26\pythonw.exe"  "path\script.pyw"

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


Re: Trouble with running java using Popen

2009-06-23 Thread norseman

Edward Grefenstette wrote:

I have a java prog I need to run at some point during the execution of
a python module.

The path to the folder containing the all the relevant java stuff
(which runs fine from the command line) is stored in pkgpath. The
relevant code is this:


os.chdir(pkgpath)
arglist = "java -Xmx1024m SemanticVectorsEvaluator ." + indexpath
SemVectPackage = Popen(arglist, stdout=PIPE, shell=True)
SemVectPackage.wait()


Here indexpath is the path to a particular index file (usually
indexpath = "./indexfolder/fileindex"), so that effectively Popen
should be running the equivalent of the shell command:
-
java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex
-
which, again, runs fine in the terminal.

However running the program returns the following error (echoed from
shell, doesn't interrupt prog):
-
Exception in thread "main" java.lang.NoClassDefFoundError:
SemanticVectorsEvaluator
-

I have no idea why this isn't working. Anyone have any suggestions as
to how I might troubleshoot this?

Best,
Edward

=
First glance shows you using ./ in code and ../in terminal.  Might check 
that first.


Second glance shows you using Popen vs popen (OK) but is that the 
correct stdout?  It is the CHILD's stdout that is being requested here. 
(Probably what you had in mind, but ...  is it?)


 Third item - running from the terminal usually loads the terminal 
environment. Running under program control may NOT load the environment. 
This is a particular problem in Window$.  Is the difference going to 
effect your efforts?



As for Java specific problems (if any) I don't know. Another might.


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


Re: Trouble with running java using Popen

2009-06-23 Thread Chris Rebert
On Tue, Jun 23, 2009 at 2:29 PM, Edward Grefenstette wrote:
> I have a java prog I need to run at some point during the execution of
> a python module.
>
> The path to the folder containing the all the relevant java stuff
> (which runs fine from the command line) is stored in pkgpath. The
> relevant code is this:
>
 os.chdir(pkgpath)
 arglist = "java -Xmx1024m SemanticVectorsEvaluator ." + indexpath
 SemVectPackage = Popen(arglist, stdout=PIPE, shell=True)
 SemVectPackage.wait()
>
> Here indexpath is the path to a particular index file (usually
> indexpath = "./indexfolder/fileindex"), so that effectively Popen
> should be running the equivalent of the shell command:
> -
> java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex
> -
> which, again, runs fine in the terminal.
>
> However running the program returns the following error (echoed from
> shell, doesn't interrupt prog):
> -
> Exception in thread "main" java.lang.NoClassDefFoundError:
> SemanticVectorsEvaluator
> -
>
> I have no idea why this isn't working. Anyone have any suggestions as
> to how I might troubleshoot this?

Have you tried?:

arglist = ["java", "-Xmx1024m", "SemanticVectorsEvaluator", "." + indexpath]
SemVectPackage = Popen(arglist, stdout=PIPE)
SemVectPackage.wait()

Cheers,
Chris
-- 
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trouble with running java using Popen

2009-06-23 Thread Diez B. Roggisch

Edward Grefenstette schrieb:

I have a java prog I need to run at some point during the execution of
a python module.

The path to the folder containing the all the relevant java stuff
(which runs fine from the command line) is stored in pkgpath. The
relevant code is this:


os.chdir(pkgpath)
arglist = "java -Xmx1024m SemanticVectorsEvaluator ." + indexpath
SemVectPackage = Popen(arglist, stdout=PIPE, shell=True)
SemVectPackage.wait()


Here indexpath is the path to a particular index file (usually
indexpath = "./indexfolder/fileindex"), so that effectively Popen
should be running the equivalent of the shell command:
-
java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex
-
which, again, runs fine in the terminal.

However running the program returns the following error (echoed from
shell, doesn't interrupt prog):
-
Exception in thread "main" java.lang.NoClassDefFoundError:
SemanticVectorsEvaluator
-

I have no idea why this isn't working. Anyone have any suggestions as
to how I might troubleshoot this?


I'd say you got an CLASSPATH-issue here. You can add that explicitly via 
env as argument to Popen, or pass it via commandline-args.


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


Python 3.0.1 and mingw

2009-06-23 Thread smartmobili
I wanted to know if you have some patch to compile python 3.x on mingw
platform because I found some
but doesn't work very well :


make

gcc   -o python.exe \
Modules/python.o \
libpython3.0.a-lm
Could not find platform independent libraries 
Could not find platform dependent libraries 
Consider setting $PYTHONHOME to [:]
Fatal Python error: Py_Initialize: can't initialize sys standard
streams
ImportError: No module named encodings.utf_8


I have some questions about posixmodule.c, config.c and makesetup,
I can see in posixmodule that you define a INITFUNC like this :

#if (defined(_MSC_VER) || defined(__WATCOMC__) || defined
(__BORLANDC__)) &&
!defined(__QNX__)
#define INITFUNC PyInit_nt
#define MODNAME "nt"

#elif defined(PYOS_OS2)
#define INITFUNC PyInit_os2
#define MODNAME "os2"

#else
#define INITFUNC PyInit_posix
#define MODNAME "posix"
#endif

So first I tried to add || defined(MINGW32) to declare a
PyInit_nt
but after config.c
was still using PyInit_posix. How does makesetup choose to include one
function or another ?
So finally python is using PyInit_posix...


and after any idea why I got the compilation error ?
-- 
http://mail.python.org/mailman/listinfo/python-list


IDLE / Python 2.5 under Jaunty

2009-06-23 Thread duncan smith
A little off-topic perhaps, but I can't think of anywhere more likely to
contain people with answers.

I've just upgraded to Jaunty Jackalope where Python 2.6 is the default
Python version.  I'm still developing under 2.5, but IDLE now refuses to
respond to left click events (for code editing, menus etc. respond as
expected).  If I right click, then left click I can move the cursor, but
that's not ideal.  I've tried SPE which is great, but I can't find a way
of configuring the Python version, so I'm stuck with a 2.6 shell.

I've had limited success with Boa Constructor (which defaulted to Python
2.6 and wxPython 2.6).  By renaming a symlink
(/usr/lib/python2.5/site-packages/wx-2.6-gtk2-unicode.pth) I managed to
get the wx version for Python 2.5 to default to 2.8.9.1.  I've pointed
Boa at 2.5 using the interpreter chooser, but the Boa frame designer
still appears to expect wxPython 2.6 (it finds "errors" in my code and
refuses to fire up).

So, has anybody else had the left click issue with IDLE (and solved it)?
 Does anyone know how I can configure Boa to use wxPython 2.8.9.1?  Does
anyone know if it's possible to configure the Python version under SPE?

Cheers.

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


Re: C-extension 2 times slower than exe

2009-06-23 Thread Carl Banks
On Jun 23, 7:20 am, Rolf Wester  wrote:
> Philip Semanchuk wrote:
>
> > On Jun 23, 2009, at 9:51 AM, Rolf Wester wrote:
>
> >> Hi,
>
> >> I have a C++ program that I would like to steer using Python. I made the
> >> wrapper using swig and linked the code (without the main function) into
> >> a shared object. My Python script loads the extension and calls a
> >> function of the C-extension, the rest runs entirely within the
> >> C-extension. For comparison I compiled the code including the main
> >> function with the same compilation options and linked all into an exe.
> >> The main function of the exe calls the same function as my Python script
> >> does. Surprisingly the code in the Python C-extension runs twice as long
> >> as the same code in the exe. Does anyone know what could be the reason
> >> for this behaviour?
>
> > If the runtime of the C/C++ code is short, the time spent initializing
> > the Python interpreter might have a big impact on the runtime of the
> > Python version.
>
> The runtime is about 2.5 sec and 5.0 sec respectively. I not only use
> the time command to measure the time consumed but I also measure the
> time within the C-code using clock() and get similar result. So the
> Python startup time is not the reason for the runtime difference I
> found. Thank you anyway.

We can't really help you much unless you give us more details about
what you did (how did you built it, how did you time it, and how are
you calling the C extension from Python).  All we can do is throw out
possible ideas, and I will toss out a few, but if that's not it you'll
have to post details.

Are you building the extension with the same optimization flags as the
compiler?

Are you calling the C code repeatedly from inside a Python loop?

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


Forwarding keyword arguments

2009-06-23 Thread Robert Dailey
Suppose I have 2 functions like so:

def Function2( **extra ):
   # do stuff

def Function1( **extra ):
   Function2( extra )

As you can see, I would like to forward the additional keyword
arguments in variable 'extra' to Function2 from Function1. How can I
do this? I'm using Python 3.0.1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE / Python 2.5 under Jaunty

2009-06-23 Thread David Lyon
On Wed, 24 Jun 2009 00:55:14 +0100, duncan smith
 wrote:
>  Does anyone know how I can configure Boa to use wxPython 2.8.9.1?  Does
> anyone know if it's possible to configure the Python version under SPE?

It definitely is possible. In fact you need to use wxpython 2.8 with Boa.

I had a similar problem under some ubuntu version. You can install 2.6 and
2.8 wxpython. But from memory there is a wxversion ubuntu package also. 

I had to do some "force"ing as there seemed to be circular dependencies.

In the end I got it to work just fine...

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


Re: Forwarding keyword arguments

2009-06-23 Thread Stephen Hansen
> Suppose I have 2 functions like so:
>
> def Function2( **extra ):
>   # do stuff
>
> def Function1( **extra ):
>   Function2( extra )
>
> As you can see, I would like to forward the additional keyword
> arguments in variable 'extra' to Function2 from Function1. How can I
> do this? I'm using Python 3.0.1


def Function1(**extra):
Function2(**extra)

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


Re: Forwarding keyword arguments

2009-06-23 Thread Gabriel Genellina
En Tue, 23 Jun 2009 20:57:36 -0300, Robert Dailey   
escribió:



Suppose I have 2 functions like so:

def Function2( **extra ):
   # do stuff

def Function1( **extra ):
   Function2( extra )

As you can see, I would like to forward the additional keyword
arguments in variable 'extra' to Function2 from Function1. How can I
do this? I'm using Python 3.0.1


Function2(**extra)
See http://docs.python.org/3.0/reference/expressions.html#calls

--
Gabriel Genellina

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


Re: Forwarding keyword arguments

2009-06-23 Thread Robert Dailey
On Jun 23, 7:34 pm, "Gabriel Genellina" 
wrote:
> En Tue, 23 Jun 2009 20:57:36 -0300, Robert Dailey   
> escribió:
>
> > Suppose I have 2 functions like so:
>
> > def Function2( **extra ):
> >    # do stuff
>
> > def Function1( **extra ):
> >    Function2( extra )
>
> > As you can see, I would like to forward the additional keyword
> > arguments in variable 'extra' to Function2 from Function1. How can I
> > do this? I'm using Python 3.0.1
>
> Function2(**extra)
> Seehttp://docs.python.org/3.0/reference/expressions.html#calls
>
> --
> Gabriel Genellina

Thanks for the answer. I did look through the docs but I missed it I
guess.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Forwarding keyword arguments

2009-06-23 Thread Ben Finney
Robert Dailey  writes:

> Suppose I have 2 functions like so:
> 
> def Function2( **extra ):
># do stuff
> 
> def Function1( **extra ):
>Function2( extra )

(Style note: The Python style guide, PEP 8, would have the above code
written as::

def function2(**extra):
# do stuff

def function1(**extra):
function2(extra)

See http://www.python.org/dev/peps/pep-0008> for a sensible style
guide for Python code.)

> As you can see, I would like to forward the additional keyword
> arguments in variable 'extra' to Function2 from Function1. How can I
> do this? I'm using Python 3.0.1

The syntax for “collect remaining positional arguments into a sequence”
in a function definition versus “unpack the values from this sequence
into positional arguments” in a function call are intentionally
similar::

def bar(spam, eggs, beans):
pass

def foo(*args):
bar(*args)

Likewise for the syntax for “collect remaining keyword arguments into a
mapping” in a function definition versus “unpack the items from this
mapping into keyword arguments” in a function call::

def function2(spam, eggs, beans):
pass

def function1(**kwargs):
function2(**kwargs)

For more detail, see the language reference section explaining calls
http://docs.python.org/reference/expressions.html#calls>.

-- 
 \  “A society that will trade a little liberty for a little order |
  `\ will lose both, and deserve neither.” —Thomas Jefferson, in a |
_o__)letter to Madison |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Mac] file copy

2009-06-23 Thread Michael Torrie
Tobias Weber wrote:
> Why "so"? shutil does not use bin/cp!

That's good to know.  I had always thought that that was what shutils
did, but you're right; it does not.

That said, since cp indeed *can* copy resource forks on Tiger and up,
you could use subprocess to call it.

Just as an aside, your response to a couple of the suggestions in this
thread has been a bit brusque, even given the normal limits of e-mail
communications.  While it's true that nothing so far has been quite what
you wanted, I'm sure that everyone has certainly tried to help you find
a solution by throwing out different ideas!  It is also true that for
many people resources forks are not at all necessary, which is probably
why someone mentioned that before, perhaps hoping to save you work.
Anyways, I certainly hope you do get something working.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: walking a directory with very many files

2009-06-23 Thread Steven D'Aprano
On Tue, 23 Jun 2009 10:29:21 -0400, Mel wrote:

> Steven D'Aprano wrote:
> 
>> Lawrence D'Oliveiro wrote:
>> 
 Ok, now pipe ls to less, take three days to browse through all the
 filenames to locate the file you want to see.
>>> 
>>> Sounds like you're approaching the issue with a GUI-centric mentality,
>>> which is completely hopeless at dealing with this sort of situation.
>> 
>> Piping the output of ls to less is a GUI-centric mentality?
> 
> Yeah.  The "dump it on the user" idea, or more politely "can't decide
> anything until the user has seen everything" is evident in the most
> "characteristic" GUIs.


Perhaps you're using different GUIs to me. In my experience, most GUIs 
tend to *hide* data from the user rather than give them everything under 
the sun.

The classic example is Windows, which hides certain files in the GUI file 
manager even if you tell it to show all files.


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


Re: Trouble with running java using Popen

2009-06-23 Thread Edward Grefenstette
Bingo. I was running the python script in GNU script, and it wasn't
loading my bash config file properly. Have fixed it by
altering .screenrc and now the code runs fine. Would have never
guessed to look if you hadn't mentioned it, cheers!

Best,
Ed

On Jun 23, 11:29 pm, "Diez B. Roggisch"  wrote:
> Edward Grefenstette schrieb:
>
>
>
> > I have a java prog I need to run at some point during the execution of
> > a python module.
>
> > The path to the folder containing the all the relevant java stuff
> > (which runs fine from the command line) is stored in pkgpath. The
> > relevant code is this:
>
>  os.chdir(pkgpath)
>  arglist = "java -Xmx1024m SemanticVectorsEvaluator ." + indexpath
>  SemVectPackage = Popen(arglist, stdout=PIPE, shell=True)
>  SemVectPackage.wait()
>
> > Here indexpath is the path to a particular index file (usually
> > indexpath = "./indexfolder/fileindex"), so that effectively Popen
> > should be running the equivalent of the shell command:
> > -
> > java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex
> > -
> > which, again, runs fine in the terminal.
>
> > However running the program returns the following error (echoed from
> > shell, doesn't interrupt prog):
> > -
> > Exception in thread "main" java.lang.NoClassDefFoundError:
> > SemanticVectorsEvaluator
> > -
>
> > I have no idea why this isn't working. Anyone have any suggestions as
> > to how I might troubleshoot this?
>
> I'd say you got an CLASSPATH-issue here. You can add that explicitly via
> env as argument to Popen, or pass it via commandline-args.
>
> Diez

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


Re: Measuring Fractal Dimension ?

2009-06-23 Thread Aahz
In article ,
Mark Dickinson   wrote:
>On Jun 22, 7:43=A0pm, David C. Ullrich  wrote:
>>
>> Surely you don't say a curve is a subset of the plane and
>> also talk about the integrals of verctor fields over _curves_?
>> [snip rest of long response that needs a decent reply, but
>>  possibly not here... ]
>
>I wonder whether we can find a better place to have this discussion; I
>think there are still plenty of interesting things to say, but I fear
>we're rather abusing the hospitality of comp.lang.python at the moment.

As long as it's confined to this thread, I certainly have no objection;
right now, this thread is occupying only a small fractin of c.l.py
bandwidth.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.0.1 and mingw

2009-06-23 Thread Kay Schluehr
On 24 Jun., 00:59, smartmobili  wrote:
> I wanted to know if you have some patch to compile python 3.x on mingw
> platform because I found some
> but doesn't work very well :
>
> make
>
> gcc   -o python.exe \
> Modules/python.o \
> libpython3.0.a-lm
> Could not find platform independent libraries 
> Could not find platform dependent libraries 
> Consider setting $PYTHONHOME to [:]
> Fatal Python error: Py_Initialize: can't initialize sys standard
> streams
> ImportError: No module named encodings.utf_8
>
> I have some questions about posixmodule.c, config.c and makesetup,
> I can see in posixmodule that you define a INITFUNC like this :
>
> #if (defined(_MSC_VER) || defined(__WATCOMC__) || defined
> (__BORLANDC__)) &&
> !defined(__QNX__)
> #define INITFUNC PyInit_nt
> #define MODNAME "nt"
>
> #elif defined(PYOS_OS2)
> #define INITFUNC PyInit_os2
> #define MODNAME "os2"
>
> #else
> #define INITFUNC PyInit_posix
> #define MODNAME "posix"
> #endif
>
> So first I tried to add || defined(MINGW32) to declare a
> PyInit_nt
> but after config.c
> was still using PyInit_posix. How does makesetup choose to include one
> function or another ?
> So finally python is using PyInit_posix...
>
> and after any idea why I got the compilation error ?

Why on earth do you want to compile Python 3.0.1?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beauty and Fitness

2009-06-23 Thread Aahz
In article <7a73lrf1totc...@mid.uni-berlin.de>,
Diez B. Roggisch  wrote:
>
>My god, these days they allow just anybody to spam, even f***tards that 
>are to stupid to include the actual URL of the spam they want to divulge.

Thank you for reposting the spam in its entirety, with special thanks
for munging your address so I can't even chide you privately.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urllib2 urlopen takes too much time

2009-06-23 Thread Aahz
In article ,
=?UTF-8?Q?Filip_Gruszczy=C5=84ski?=   wrote:
>
>I have encountered a performance problem using suds, which was traced
>down to _socket.recv. I am calling some web services and each of them
>uses about 0.2 sec and 99% of this time is spent on urllib2.urlopen,
>while the rest of the call is finished in milliseconds. 

What happens if you use urlopen() by itself?
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Meta question: disappearing posts (was Re: calculating a self.value, self.randomnum = normalvariate(x, y))

2009-06-23 Thread Aahz
In article ,
Ross Ridge   wrote:
>Aahz  wrote:
>>Piet van Oostrum   wrote:
>>>
I notice that I see several postings on news:comp.lang.python that are
>>>replies to other postings that I don't see. 
>>
>>As stated previously, my suspicion is that at least some is caused by a
>>problem with MIME messages and the mail->news gateway on python.org.
>
>I'm not sure what MIME would have to do with it, but Piet van Oostrum's
>problem is almost certainly as result of the python.org mail to news
>gateway mangling the References header.  The missing postings he's looking
>for don't actually exist.  Just go up the thread one more posting and
>you'll find the message that was being replied to.

While that's also a bug in Mailman (I have a long-standing to-do item to
fix that), there are also plenty of posts that simply aren't showing up
in c.l.py.  As I said, I'm pretty sure (based on what was happening with
c.l.py.announce) that it's some kind of weird problem with the mail->news
gateway with MIME posts.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE / Python 2.5 under Jaunty

2009-06-23 Thread Lie Ryan
duncan smith wrote:
> I've just upgraded to Jaunty Jackalope where Python 2.6 is the default
> Python version.  I'm still developing under 2.5, but IDLE now refuses to
> respond to left click events (for code editing, menus etc. respond as
> expected).  If I right click, then left click I can move the cursor, but
> that's not ideal.

For the meantime, you should search/file a bug report on Launchpad
(Ubuntu's bugtracker) on: https://launchpad.net/ubuntu/ if you haven't
already done so.

I just tried idle 2.6 (python 2.6, Tk 8.4) on Gentoo, and left-clicking
seems to run fine (although I'm a bit unclear on what kinds of
left-clicking IDLE refuses to respond to).

On the reports to Launchpad, don't forget to include the versions of
python, idle, and Tk as reported on Help > About.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: generator expression works in shell, NameError in script

2009-06-23 Thread ssc
On Jun 18, 10:49 am, Jon Clements  wrote:
> Why are you doing this? I'm assuming a code to title look up is
> required (don't forget military, royal and honorable titles
> etc... :) )

I'm in New Zealand. Hardly any need for military titles, rarely any
for royal and damn sure none for honorable :-D (scnr)
-- 
http://mail.python.org/mailman/listinfo/python-list


Best way to enumerate classes in a module

2009-06-23 Thread Дамјан Георгиевски
I need to programmaticaly enumerate all the classes in a given module. 
Currently I'm using dir(module) but the Notice on the documentation page 
[1]  says "dir() is supplied primarily as a convenience for use at an 
interactive prompt" so that kind of scares me.

Is there a better approach?

If there is, how do I get all the classes of the current module?


[1] http://docs.python.org/library/functions.html#dir

-- 
дамјан ( http://softver.org.mk/damjan/ )

Q: What's tiny and yellow and very, very, dangerous?
A: A canary with the super-user password.

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


Re: walking a directory with very many files

2009-06-23 Thread Lawrence D'Oliveiro
In message , Steven 
D'Aprano wrote:

> On Tue, 23 Jun 2009 10:29:21 -0400, Mel wrote:
> 
>> Steven D'Aprano wrote:
>> 
>>> Lawrence D'Oliveiro wrote:
>>> 
> Ok, now pipe ls to less, take three days to browse through all the
> filenames to locate the file you want to see.
 
 Sounds like you're approaching the issue with a GUI-centric mentality,
 which is completely hopeless at dealing with this sort of situation.
>>> 
>>> Piping the output of ls to less is a GUI-centric mentality?
>> 
>> Yeah.  The "dump it on the user" idea, or more politely "can't decide
>> anything until the user has seen everything" is evident in the most
>> "characteristic" GUIs.
> 
> Perhaps you're using different GUIs to me. In my experience, most GUIs
> tend to *hide* data from the user rather than give them everything under
> the sun.

Which is getting a bit away from what we're discussing here, but certainly 
it is characteristic of GUIs to show you all 400,000 files in a directory, 
or at least try to do so, and either hang for half an hour or run out of 
memory and crash, rather than give you some intelligent way of prefiltering 
the file display up front.

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


Re: I look for private Python Index server on my local network... What do you use ?

2009-06-23 Thread Chris Withers

Klein Stéphane wrote:
I wonder what Python Index server (like as pypi.python.org) do you use in 
your corporation for handle your private python eggs ?


I found three solutions :

* http://pypi.python.org/pypi/basketweaver/0.1.2-r6
* http://pypi.python.org/pypi/pypi/2005-08-01
* http://pypi.python.org/pypi/EggBasket/0.6.1b

Do you know another software ? 


http://pypi.python.org/pypi/haufe.eggserver/0.2.5


What do you use ?


I actually just store the private eggs directly in a subversion 
repository and that the url of the folder the eggs live in to find-links.


cheers,

Chris

--
Simplistix - Content Management, Zope & Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tutorial on working with Excel files in Python (without COM and crossplatform!) at EuroPython 2009

2009-06-23 Thread Chris Withers

Jeremiah Jester wrote:

Chris,
Do you have any online tutorial for this topic? 


I'm afraid not currently...

Chris

--
Simplistix - Content Management, Zope & Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to enumerate classes in a module

2009-06-23 Thread Peter Otten
Дамјан Георгиевски wrote:

> I need to programmaticaly enumerate all the classes in a given module.
> Currently I'm using dir(module) but the Notice on the documentation page
> [1]  says "dir() is supplied primarily as a convenience for use at an
> interactive prompt" so that kind of scares me.
> 
> Is there a better approach?
> 
> If there is, how do I get all the classes of the current module?

inspect.getmembers(module, inspect.isclass), but this uses dir() internally.
You may have to remove imported classes:

>>> def getclasses(module):
... def accept(obj):
... return inspect.isclass(obj) and module.__name__ == 
obj.__module__
... return [class_ for name, class_ in inspect.getmembers(module, 
accept)]
...
>>> getclasses(inspect)
[, , ...]

Peter

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