Re: module: zipfile.writestr - line endings issue

2007-08-15 Thread Suresh Babu Kolla
Paul Carter wrote:
> On Aug 14, 1:32 pm, towers <[EMAIL PROTECTED]> wrote:
>> Thanks - your code works for me also.
>>
>> But I still get the issue when I read the file directly and add it to
>> the archive.
>>
>> Say if I:
>>
>> 1. Use the test.csv file created with your code - currently the line
>> endings look good (viewed in notepad on Win XP)
>> 2. Run the following code:
>>
>> # begin code
>> import zipfile
>> import os.path
>>
>> # Now, create the zipfile
>> dfile = open('test.csv', 'r')
>> zip_file = zipfile.ZipFile(r'C:\temp\ice\line endings\test.zip', 'w',
>> zipfile.ZIP_DEFLATED)
>> zip_file.writestr('test.csv',dfile.read())
>> dfile.close()
>> zip_file.close()
>>
>> 3. Then extract the file and the file endings have been corrupted. Now
>> one long line in notepad. (Other programs interpret correctly though.)
>>
>> Maybe the issue lies with this way (i.e. dfile.read()) of writing the
>> file to the archive...possibly.
>>
>> Damon
>>
> 
> Please don't top post.
> 
> The problem is with how you are opening the file. You need to open in
> binary mode if you wish to read your file unaltered. Also, file() is
> preferred over open() these days I think. Use:
> 
> dfile = file('test.csv', 'rb')

 From Python 2.5 library documentation.


  When opening a file, it's preferable to use `open()' instead of
  invoking this constructor directly.  `file' is more suited to type
  testing (for example, writing `isinstance(f, file)').


Python documentation seem to recommend using open(). I personally prefer
to use open, just because python open has same signature as POSIX open, 
even beginner programmers can understand the intent of the code clearly.

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


What does r"""any text""" mean ?

2007-08-15 Thread Alexander Eisenhuth
... as you can find in os.py at line 1 ?

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


Re: Fast kNN from python

2007-08-15 Thread Janto Dreijer
On Aug 14, 9:27 pm, Sean Davis <[EMAIL PROTECTED]> wrote:
> On Aug 14, 6:16 am, Janto Dreijer <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi!
>
> > I am looking for a Python implementation or bindings to a library that
> > can quickly find k-Nearest Neighbors given an arbitrary distance
> > metric between objects. Specifically, I have an "edit distance"
> > between objects that is written in Python.
>
> > I haven't looked at the methods in detail but I think I'm looking for
> > one of the data structures listed 
> > onhttp://en.wikipedia.org/wiki/Metric_trees
> > (i.e. vp-trees, cover trees, m-trees or bk trees). But I might be
> > wrong. An approximatekNNwould also work.
>
> > If there doesn't exist such an implementation yet, any advice on a
> > library I can wrap myself would also be appreciated.
>
> > Thanks!
> > Janto
>
> Have you looked at using Rpy and R?  There are probably severalknn
> implementations that then become accessible to you (although I haven't
> checked recently).
>
> Sean

Interesting. I have not looked at that. I can't really find an R
package that does what I want, so any suggestions are appreciated.

Janto

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


Re: module: zipfile.writestr - line endings issue

2007-08-15 Thread towers
> > Please don't top post.
>
> > The problem is with how you are opening the file. You need to open in
> > binary mode if you wish to read your file unaltered. Also, file() is
> > preferred over open() these days I think. Use:
>
> > dfile = file('test.csv', 'rb')
>
>  From Python 2.5 library documentation.
>
> 
>   When opening a file, it's preferable to use `open()' instead of
>   invoking this constructor directly.  `file' is more suited to type
>   testing (for example, writing `isinstance(f, file)').
> 
>
> Python documentation seem to recommend using open(). I personally prefer
> to use open, just because python open has same signature as POSIX open,
> even beginner programmers can understand the intent of the code clearly.
>
> Kolla


Opening in binary mode solves the issue. Thanks very much for the help.

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


Re: curses library

2007-08-15 Thread Michael Bentley

On Aug 14, 2007, at 11:10 AM, Ghirai wrote:

> I need to write a console application.
>
> Are there any wrappers around curses/ncurses?
> Or any other similar libraries?

It looks like Curses Tk still exists: http://www.schwartzcomputer.com/ 
tcl-tk/tcl-tk.html

It probably requires a recompile of Tk and maybe Python but may allow  
for the same code to work as console and gui?  If it works that way,  
that's a plus for Tkinter...

regards,
Michael
---
Simplicity is the ultimate sophistication. -Leonardo da Vinci



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


Re: What does r"""any text""" mean ?

2007-08-15 Thread Bjoern Schliessmann
Alexander Eisenhuth wrote:

> ... as you can find in os.py at line 1 ?

Please don't split your request between subject and body.

String literals enclosed in triple quotes are multiline strings.
String literals prefixed by "r" are raw strings.

http://docs.python.org/ref/strings.html

Regards,


Björn

-- 
BOFH excuse #71:

The file system is full of it

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


Re: What does r"""any text""" mean ?

2007-08-15 Thread Claudio Corrodi
Hi Alexander,

Alexander Eisenhuth wrote:
> ... as you can find in os.py at line 1 ?
This is a raw string. Raw strings don't interpret the escape sequences.
Try this:
>>> print 'a\nb\tc'
a
b   c
>>> print r'a\nb\tc'
a\nb\tc

You needn't use the raw string for printing the backslashes. You can
escape them like this:
>>> print 'a\\nb\\tc'
a\nb\tc


> Regards Alexander
Regards,
Claudio
-- 
http://mail.python.org/mailman/listinfo/python-list


moving files in a seperate thread (and/or with progress?)

2007-08-15 Thread Jorgen Bodde
Hi all,

I want to make a small batch copy tool that scans for certain files,
and copies them to a specified directory. Since the files are huge
(AVI / DIVX) typical 300 to 700 Mb, I want to provide the user with
some feedback during the file copy.

Here is my dillemma; When I use shutil.move(..,..) I have to wait
until it's done, there is no feedback, so the GUI basically hangs.
However, shutil.move can be fast because it intelligently renames the
file when it is on the same medium, but slow when it moves to a
different one.
When I use my own implementation of a move mechanism that provides
feedback, I lose that intelligence, and I might slow down the copy
process unneccessarily.

When I move files, feedback is handy to have, but not neccesary so I
thought I can also call shutil.move from a seperate thread so the main
GUI stays responsive. What are my options in aborting a move by
killing the thread or are there other (3rdparty) modules I might use
to get better move or copy performances?

Just opening the file, performing a block copy myself seems like it
will slow down the transfer, but up until now I found no way to move
or copy with progress or abilities to abort the file transfer..

Any ideas?

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


Re: JPype - passing to Java main

2007-08-15 Thread Gary Duzan
In article <[EMAIL PROTECTED]>,
 <[EMAIL PROTECTED]> wrote:
>Good point Laurent. Here is the error produced when I try to access
>main() using
>'com.JPypeTest.main("arg")'
>
>The original code is pasted at the top of this thread. I only added
>'com.JPypeTest.main("arg")' which causes the error below
>
>-ERROR_-
>  File "tester.py", line 10, in 
>com.JPypeTest.main("arg")
>RuntimeError: No matching overloads found. at src/native/common/
>jp_method.cpp:121
>--END ERROR-
>
>Thanks,
>Sarah

   Just a guess, but try com.JPypeTest.main(["arg"]).

Gary Duzan
Motorola HNM



>On Aug 14, 8:03 am, Laurent Pointal <[EMAIL PROTECTED]> wrote:
>> [EMAIL PROTECTED] a écrit :
>>
>> >> Try this:
>> >> com.JPypeTest.main("arg")
>>
>> >> Ian
>>
>> > Thanks for your suggestion, but it doesn't work (produces an error).
>>
>> This is where you should have copy/pasted the error.
>>
>> ;-)
>>
>>
>>
>> > Does anybody else have any ideas?
>>
>> Sorry, no.
>
>


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

access error

2007-08-15 Thread Sreerama Veeranna
Hi all,
  
Sometimes, python gets crash by giving access error sometimes doesn’t.
Why is this?
 
 
Regards
Sreerama V

[ The information contained in this e-mail is confidential and is intended for 
the named recipient only. If you are not the named recipient, please notify us 
by telephone on +44 (0)1666 580 000 immediately, destroy the message and delete 
it from your computer. Silver Software has taken every reasonable precaution to 
ensure that any attachment to this e-mail has been checked for viruses. 
However, we cannot accept liability for any damage sustained as a result of any 
such software viruses and advise you to carry out your own virus check before 
opening any attachment. Furthermore, we do not accept responsibility for any 
change made to this message after it was sent by the sender.]
-- 
http://mail.python.org/mailman/listinfo/python-list

Combinatorial of elements in Python?

2007-08-15 Thread Sebastian Bassi
I have 2 (or more) groups of elements, and I want to get all possible
unique combinations from all of them. Is there a build-in method to do
it?

ADictionary={"one":["A","B","C","D"],"two":["H","I"]}

I want to have all possible combinations from "one" and "two", that is:

AH
BI
CH
DI
AI
BH
CI
DH

Sounds easy, but is not :)


-- 
Sebastián Bassi (セバスティアン)
Diplomado en Ciencia y Tecnología.
GPG Fingerprint: 9470 0980 620D ABFC BE63 A4A4 A3DE C97D 8422 D43D
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: creating and appending to a dictionary of a list of lists

2007-08-15 Thread Ant
On Aug 15, 3:30 am, [EMAIL PROTECTED] wrote:
> Hey,
>
> I started with this:
>
> factByClass = {}
>
...
> def update(key, *args):
> x = factByClass.setdefault(key, [[], [], [], [] ])
> for i, v in enumerate(args):
> x[i].append(v)
>
> Is there a better way?

Well, the following is perhaps neater:

>>> factByClass = defaultdict(lambda: [[],[],[],[]])
>>> def update(key, *args):
...   map(list.append, factByClass[key], args)
...
>>> update('one', 1, 2, 3, 4)
>>> update('one', 5, 6, 7, 8)
>>> update('two', 9, 10, 11, 12)
>>>
>>> print factByClass
defaultdict( at 0x00F73430>, {'two': [[9], [1
0], [11], [12]], 'one': [[1, 5], [2, 6], [3, 7], [4, 8]]})

It abuses the fact that list.append modifies the list in place -
normally you would use map to get a new list object. In this case the
new list returned by map is just a list of None's (since append
returns None - a common idiom for functions that operate by side
effect), and so is not used directly.

--
Ant...

http://antroy.blogspot.com/



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


Re: buggie in else syntax ?

2007-08-15 Thread stef mientki
Thomas Jollans wrote:
> On Tuesday 14 August 2007, stef mientki wrote:
>   
>> hello,
>>
>> I've the idea that the "else" syntax is not always handled correctly,
>> or I'm overlooking something.
>>
>> This pieces of code are automatic translation from another language,
>> sometimes it works, sometimes it doesn't ???
>>
>> This piece of code works nice:
>>
>> a = 2
>>
>> def JSM (line_nr):
>>   print line_nr
>>
>> if a>3:
>> print 'asddas'
>> else: JSM(230) ; \<== this is the problem line, that's ok here
>> print 'aaps'
>>
>> While this piece of code gives a syntax error:
>>
>> #Function button_antidender(bit in pin,sbyte in out
>> Button_Counter_Temp,byte in demp) return bit is
>> def button_antidender ( pin, button_counter_temp, demp ):
>>  #serial_hw_write(counter)
>> Serial_HW_Write ( button_counter_temp ) ;JSM(226)
>> if JSM(227) and (   button_counter_temp >= 0 ):
>> if JSM(228) and (  pin == on ):
>> button_counter_temp =  button_counter_temp  +  1
>> ;JSM(229)
>> else: JSM(230) ;
>> \<=== SYNTAX ERROR
>> 
>
> is there a newline before the backslash ? Or a space after the backslash but 
> before the newline ?
>
>   
I investigated this some further in a hex editor,
and indeed sometimes there's a space,
ok that's my stupid mistake.

But I found a situation that also in the very simple example always 
gives a syntax error

a = 2
b = 5

def JSM (line_nr):
print line_nr

if a>3:
print 'asddas'
else: JSM(230) ; \
if b>3:  <== SYNTAX ERROR pointing to the "f" of if
print 'b'
else:
print 'c'
print 'aaps'

And I don't see the syntax error.
And if you're interested in the hex file data:
  65 6C 73 65 3A 20 4A 53 4D 28 32 33 30 29 20 3B 20 5C 0D 0A

btw, I now split the else line over more than 1 line, and everything is 
perfect.

thanks,
Stef Mientki

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


Re: What order does info get returned in by os.listdir()

2007-08-15 Thread Jeremy C B Nicoll
Jeremy C B Nicoll <[EMAIL PROTECTED]> wrote:
 
> When I use os.listdir() to return that list of leaf values, I do seem to
> get them in alphabetical order, A before B before C etc, but the
> ~-prefixed ones are returned after the Z-prefixed files rather than before
> the A-ones.

Thanks to people who replied here, and by email.

I've some supplementary questions... my original code was looking at each
leafname in turn via

  for leaf in os.listdir(path):
  wholefile = os.path.join(path,leaf)
  if os.path.isfile(wholefile):
 if leaf.startswith("~"):

etc.  But I now realise I might alternatively do something like:

  leaflist = os.listdir(path)
  
  for leaf in leaflist:

How would I sort leaflist in a way that mimics the sort order that XP shows
me things under?  



Secondly, my code is wasting time looking at subdirectories/files which I
already know I'm not interested in.  Is there a way to restrict listdir to,
say, only return info about subdirectories, or only about dirs/files whose
names match a pattern?


Thirdly, once I've go a list of leafnames, somehow, is there a way to ask
Python if a specific leaf-value is in that list, without explicitly looping
through the items in the list?

-- 
Jeremy C B Nicoll - my opinions are my own.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython before MainLoop

2007-08-15 Thread samwyse
Chris Mellon wrote:
> On 8/9/07, Heikki Toivonen <[EMAIL PROTECTED]> wrote:
> 
>>[david] wrote:
>>
>>>I'd like to refresh the display before I start the main loop.

If your window isn't able to interact with the user, then I'd consider 
it a splash screen, no matter if it does look exactly like your main 
application interface.

>>We have this kind of situation in Chandler, where we display and update
>>the splash screen before we enter MainLoop.
>>
[...]
>>3. The splash screen refresh is basically: draw new stuff,
>>self.Layout(), self.Update(), wx.Yield()
>>http://lxr.osafoundation.org/source/chandler/application/Application.py#1421

Looking at the Chandler code suggests a solution to [david]'s original 
problem.  It is possible that, on Windows only, he may need to call 
Update to finish painting the display.

1432 self.Layout()
1433 if wx.Platform == '__WXMSW__':
1434 self.Update()
1435 wx.GetApp().Yield(True)

> wxYield spins the event loop in place. This can have some serious
> consequences if you aren't very careful with your usage, like
> recursively entering event handlers. I generally consider it an
> experts only interface, and avoid it.

I'll confess to being one of those old-school programmers who, back in 
the day, wrote his code around big select loops instead of using 
threads, but I'm intriged by the "experts only" designation.  Can 
someone explain further?  Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


PyCon 2008 - Call for Tutorial Ideas

2007-08-15 Thread Greg Lindstrom
It's hard to believe, but the planning for PyCon 2008 is underway.  PyCon,
an annual gathering of Python enthusiasts -- nearly 600 in Dallas last year
-- will be held in Chicago next March 14-16, with one full "pre-conference"
day, March 13, set aside for tutorials; classes given by Python honchos on
various topics.  These sessions last 3 hours (plus a break) and in general
are more detailed than the talks given during the actual conference.  Right
now, we need to know what YOU want to see covered in these sessions.
 Testing, GUI, web-apps, database, basic Python, advanced Python, objects,
anything and everything Python is on the table at this point.  We have to
narrow the field down to 10 or 15 and then find qualified presenters, so now
is the time to start gathering ideas.

What tutorials would you like to see offered?  Please response to:
[EMAIL PROTECTED]

Thanks,

Greg Lindstrom
Tutorial Coordinator, PyCon 2008
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: buggie in else syntax ?

2007-08-15 Thread Ant
On Aug 15, 9:40 am, stef mientki <[EMAIL PROTECTED]> wrote:
> Thomas Jollans wrote:
...
> else: JSM(230) ; \
> if b>3:  <== SYNTAX ERROR pointing to the "f" of if

This is equivalent to:

> else: JSM(230) ;   if b>3:

If statements (any compund statements in fact such as for loops etc)
*must* start on a new line (with indentation as necessary):

http://docs.python.org/ref/compound.html

--
Ant...

http://antroy.blogspot.com/


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


Re: Combinatorial of elements in Python?

2007-08-15 Thread Wildemar Wildenburger
Sebastian Bassi wrote:
> I have 2 (or more) groups of elements, and I want to get all possible
> unique combinations from all of them. Is there a build-in method to do
> it?
>
> ADictionary={"one":["A","B","C","D"],"two":["H","I"]}
>
> I want to have all possible combinations from "one" and "two", that is:
>
> AH
> BI
> CH
> DI
> AI
> BH
> CI
> DH
>
> Sounds easy, but is not :)
>
>   
Oh but it is:

>>> ADictionary={"one":["A","B","C","D"],"two":["H","I"]}
>>> result = set()
>>> for one in ADictionary["one"]:
... for two in ADictionary["two"]:
... result.add(one + two)
... 
>>> result
set(['CI', 'CH', 'DH', 'DI', 'AI', 'AH', 'BH', 'BI'])


/W

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


Guitar Reviews

2007-08-15 Thread cvezvu
Custom guitar, acoustic guitar, electric guitars, reviews,
specifications, pictures, prices, all here!

http://pro-guitars.blogspot.com/


Free guitars

http://freeguitars.blogspot.com/

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


Re: Combinatorial of elements in Python?

2007-08-15 Thread François Ingelrest
> > I have 2 (or more) groups of elements, and I want to get all possible
> > unique combinations from all of them. Is there a build-in method to do
> > it?
> >>> ADictionary={"one":["A","B","C","D"],"two":["H","I"]}
> >>> result = set()
> >>> for one in ADictionary["one"]:
> ... for two in ADictionary["two"]:
> ... result.add(one + two)
> ...
> >>> result
> set(['CI', 'CH', 'DH', 'DI', 'AI', 'AH', 'BH', 'BI'])

With a list comprehension:

>>> d={"one":["A","B","C","D"],"two":["H","I"]}
>>> [a+b for a in d['one'] for b in d['two']]
['AH', 'AI', 'BH', 'BI', 'CH', 'CI', 'DH', 'DI']
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: module: zipfile.writestr - line endings issue

2007-08-15 Thread Paul Carter
On Aug 15, 3:33 am, Suresh Babu Kolla <[EMAIL PROTECTED]> wrote:
> Paul Carter wrote:
>
> > The problem is with how you are opening the file. You need to open in
> > binary mode if you wish to read your file unaltered. Also, file() is
> > preferred over open() these days I think. Use:
>
> > dfile = file('test.csv', 'rb')
>
>  From Python 2.5 library documentation.
>
> 
>   When opening a file, it's preferable to use `open()' instead of
>   invoking this constructor directly.  `file' is more suited to type
>   testing (for example, writing `isinstance(f, file)').
> 
>
> Python documentation seem to recommend using open(). I personally prefer
> to use open, just because python open has same signature as POSIX open,
> even beginner programmers can understand the intent of the code clearly.
>
> Kolla

Yeah, you're right. I know I had read that file() was preferred
somewhere, but obviously it wasn't a good source. Thanks for the
correction!

--
Paul

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


Re: Guitar Reviews

2007-08-15 Thread Dustan
On Aug 15, 7:32 am, [EMAIL PROTECTED] wrote:


>>> op.mother.speak()
Congratulations! You've just given your email address to millions of
people across Usenet!
What do you have to say for yourself?
>>> op.respond()
Awww, jeez, why'd y'all have to bring my mother into this?
>>> op.mother.speak()
You're grounded for a week!
>>> op.respond()
But-
Ah! No buts!
But-
To your room, mister!
Ok.
>>> # wha-?

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


Re: Who told str() to round my int()'s!!!

2007-08-15 Thread A.T.Hofkamp
On 2007-08-11, Adam W. <[EMAIL PROTECTED]> wrote:
> After a fair amount of troubleshooting of why my lists were coming
> back a handful of digits short, and the last digit rounded off, I
> determined the str() function was to blame:
>
 foonum
> 0.0071299720384678782
 str(foonum)
> '0.00712997203847'

>
> Why in the world does str() have any business rounding my numbers, and
> how do I get around this?

You have got a few good reactions already. What is not mentioned yet however is
the difference between str() and repr().


Python has two ways to stringify an object:

str() is intended to deliver a 'human-readable' representation of its argument,
and typically, humans think a few digits of a float is enough.

The repr() on the other hand is intended to deliver a 'machine-reproducible'
string representation of its argument, ie after "y = eval(repr(x))" y == x
should hold.

Note that no rounding occurs with the floating point number, arguments of both
str() and repr() are not changed.


So, depending on your intentions of str(foonum), you should either explicitly
format your floating point number yourself (ie if you want a more precise
human-readable representation of the number), or you should use repr() (if you
intend to use the string representation for reproducing the same object
elsewhere by a machine).


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


ming on win32 anyone ? [help a noob]

2007-08-15 Thread daz.diamond
hoping someone can help ...

how do I install ming (with python) on win32? have downloaded the tar.gz 
of ming-0.3.0 which doesn't have a handy self-installer, and I'm 
absolutely foxed as to what to do next ... the install instructions in 
the package seem to be linux oriented, which to me may as well be in greek

any clues much appreciated, thx

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


Re: PyCon 2008 - Call for Tutorial Ideas

2007-08-15 Thread Jeff McNeil
Now, I'm not sure if this has been covered in great detail anywhere,
but I'd love to see something touching on interoperability with .Net
web services.

I've had a lot of success getting Python moved into our organization,
but this is where it gets difficult.  While I'm product focused, our
business focused groups rely very heavily on .Net, WS-*, WCF, and
SOAP.

It's one thing to get ZSI working with simple SOAP calls, it's quite
another to tie into a large-scale .Net based system.  I've managed to
get it working where I need to, but if I've found it difficult, I'm
sure others have as well.

Just an idea!

Jeff

On 8/15/07, Greg Lindstrom <[EMAIL PROTECTED]> wrote:
> It's hard to believe, but the planning for PyCon 2008 is underway.  PyCon,
> an annual gathering of Python enthusiasts -- nearly 600 in Dallas last year
> -- will be held in Chicago next March 14-16, with one full "pre-conference"
> day, March 13, set aside for tutorials; classes given by Python honchos on
> various topics.  These sessions last 3 hours (plus a break) and in general
> are more detailed than the talks given during the actual conference.  Right
> now, we need to know what YOU want to see covered in these sessions.
>  Testing, GUI, web-apps, database, basic Python, advanced Python, objects,
> anything and everything Python is on the table at this point.  We have to
> narrow the field down to 10 or 15 and then find qualified presenters, so now
> is the time to start gathering ideas.
>
> What tutorials would you like to see offered?  Please response to:
> [EMAIL PROTECTED]
>
> Thanks,
>
> Greg Lindstrom
> Tutorial Coordinator, PyCon 2008
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Combinatorial of elements in Python?

2007-08-15 Thread Sean Tierney
Hi Team,

I'm trying to get Python hooked up to MySQL using MySQL-python-1.2.2

Details:
Mac OS X 10.4.x
Python2.5
MySQL 5.x.x
MySQL-python-1.2.2
gcc

Target: i686-apple-darwin8
Configured with: /private/var/tmp/gcc/gcc-5250.obj~12/src/configure
--disable-checking -enable-werror --prefix=/usr --mandir=/share/man
--enable-languages=c,objc,c++,obj-c++
--program-transform-name=/^[cg][^.-]*$/s/$/-4.0/
--with-gxx-include-dir=/include/c++/4.0.0
--build=powerpc-apple-darwin8 --with-arch=pentium-m
--with-tune=prescott --program-prefix= --host=i686-apple-darwin8
--target=i686-apple-darwin8
Thread model: posix
gcc version 4.0.1 (Apple Computer, Inc. build 5250)

When I run $ python setup.py build, I get this message:

~/Desktop/MySQL-python-1.2.2 SeanThomas$ python setup.py build
running build
running build_py
copying MySQLdb/release.py -> build/lib.macosx-10.3-fat-2.5/MySQLdb
running build_ext
building '_mysql' extension
gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk
-fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd
-fno-common -dynamic -DNDEBUG -g -O3 -Dversion_info=(1,2,2,'final',0)
-D__version__=1.2.2
-I/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5
-c _mysql.c -o build/temp.macosx-10.3-fat-2.5/_mysql.o
_mysql.c:35:23: error: my_config.h: No such file or directory
_mysql.c:41: error: parse error before string constant
_mysql.c:78: error: parse error before 'MYSQL'
_mysql.c:78: warning: no semicolon at end of struct or union
_mysql.c:81: error: parse error before '}' token
_mysql.c:81: warning: data definition has no type or storage class
_mysql.c:92: error: parse error before 'MYSQL_RES'
_mysql.c:92: warning: no semicolon at end of struct or union
_mysql.c:96: error: parse error before '}' token
_mysql.c:96: warning: data definition has no type or storage class
_mysql.c:108: error: parse error before '*' token
_mysql.c: In function '_mysql_Exception':
_mysql.c:122: error: 'c' undeclared (first use in this function)
_mysql.c:122: error: (Each undeclared identifier is reported only once
_mysql.c:122: error: for each function it appears in.)
_mysql.c:125: error: 'CR_MAX_ERROR' undeclared (first use in this function)
_mysql.c:133: error: 'CR_COMMANDS_OUT_OF_SYNC' undeclared (first use
in this function)

~100+ or more lines of error message then it ends with:

lipo: can't figure out the architecture type of: /var/tmp//cc1VlbOG.out
error: command 'gcc' failed with exit status 1


Can someone point me in the right direction?

Thanks, and Happy Wednesday.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating and appending to a dictionary of a list of lists

2007-08-15 Thread pyscottishguy
On Aug 15, 8:08 am, Ant <[EMAIL PROTECTED]> wrote:
> On Aug 15, 3:30 am, [EMAIL PROTECTED] wrote:
>
> > Hey,
>
> > I started with this:
>
> > factByClass = {}
>
> ...
> > def update(key, *args):
> > x = factByClass.setdefault(key, [[], [], [], [] ])
> > for i, v in enumerate(args):
> > x[i].append(v)
>
> > Is there a better way?
>
> Well, the following is perhaps neater:
>
> >>> factByClass = defaultdict(lambda: [[],[],[],[]])
> >>> def update(key, *args):
>
> ...   map(list.append, factByClass[key], args)
> ...>>> update('one', 1, 2, 3, 4)
> >>> update('one', 5, 6, 7, 8)
> >>> update('two', 9, 10, 11, 12)
>
> >>> print factByClass
>
> defaultdict( at 0x00F73430>, {'two': [[9], [1
> 0], [11], [12]], 'one': [[1, 5], [2, 6], [3, 7], [4, 8]]})
>
> It abuses the fact that list.append modifies the list in place -
> normally you would use map to get a new list object. In this case the
> new list returned by map is just a list of None's (since append
> returns None - a common idiom for functions that operate by side
> effect), and so is not used directly.
>
> --
> Ant...
>
> http://antroy.blogspot.com/

Nice.  I like it.  Thanks a lot!

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


Re: Retry: Question about FutureWarning

2007-08-15 Thread Paul McGuire
On Aug 14, 8:49 pm, Erik Max Francis <[EMAIL PROTECTED]> wrote:
> Steven W. Orr wrote:
> > M1.py:268: FutureWarning: hex/oct constants > sys.maxint will
> > return positive values in Python 2.4 and up
> >StartTime   = safe_dict_get ( dic, 'starttime', 0x )
> ...
> > import warnings
> > warnings.filterwarnings('ignore', category=FutureWarning)
>
> > My question is this: Why can the warning not be shut off by putting the
> > two lines in M1 where the reference exists to 0x ?
>
> You really don't want to shut off the warning; it means just what it says:
>
> Python 2.3.5 (#1, Feb  8 2005, 23:36:23)
> [GCC 3.2.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> 0x
> :1: FutureWarning: hex/oct constants > sys.maxint will return
> positive values in Python 2.4 and up
> -1
>
> Python 2.4.3 (#1, Mar 29 2006, 17:16:11)
> [GCC 3.2.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> 0x
> 4294967295L
>
> --
> Erik Max Francis && [EMAIL PROTECTED] &&http://www.alcyone.com/max/
>   San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis
>Black vinyl man with black plasticized imagination
> -- Nik Kershaw

So if by '0x' you meant -1, then change this line to use -1.
Otherwise, if you really meant 4294967295L, leave it at 0x and
move on.

-- Paul

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


Re: Combinatorial of elements in Python?

2007-08-15 Thread Mikael Olofsson
Sebastian Bassi wrote:
> I have 2 (or more) groups of elements, and I want to get all possible
> unique combinations from all of them. Is there a build-in method to do
> it?
>
> ADictionary={"one":["A","B","C","D"],"two":["H","I"]}
>
> I want to have all possible combinations from "one" and "two", that is:
> [snip]

Not at all complicated. My solution:

 >>> A={'one':['A','B','C','D'],'two':['H','I']}
 >>> [x+y for x in A['one'] for y in A['two']]
['AH', 'AI', 'BH', 'BI', 'CH', 'CI', 'DH', 'DI']

HTH
/MiO

-- 
/Mikael Olofsson
Universitetslektor (Senior Lecturer [BrE], Associate Professor [AmE])
Linköpings universitet

---
E-Mail:  [EMAIL PROTECTED]
WWW: http://www.dtr.isy.liu.se/en/staff/mikael
Phone:   +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
---
Linköpings kammarkör: www.kammarkoren.com   Vi söker tenorer och basar! 

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

Re: What order does info get returned in by os.listdir()

2007-08-15 Thread Marc 'BlackJack' Rintsch
On Wed, 15 Aug 2007 12:34:27 +0100, Jeremy C B Nicoll wrote:

> I've some supplementary questions... my original code was looking at each
> leafname in turn via
> 
>   for leaf in os.listdir(path):
>   wholefile = os.path.join(path,leaf)
>   if os.path.isfile(wholefile):
>  if leaf.startswith("~"):
> 
> etc.  But I now realise I might alternatively do something like:
> 
>   leaflist = os.listdir(path)
>   
>   for leaf in leaflist:

But this is doing something different that the above code!?

> How would I sort leaflist in a way that mimics the sort order that XP shows
> me things under?  

This depends on what XP is.  Which program?  Which locale?  How does the
locale influence that programs sorting?

> Secondly, my code is wasting time looking at subdirectories/files which I
> already know I'm not interested in.  Is there a way to restrict listdir to,
> say, only return info about subdirectories, or only about dirs/files whose
> names match a pattern?

`os.listdir()` always returns all names.  You can or have to  filter the
result if you are only interested in some of the names.  Simple pattern
matching on names can be done with `glob.glob()`.

> Thirdly, once I've go a list of leafnames, somehow, is there a way to
> ask Python if a specific leaf-value is in that list, without explicitly
> looping through the items in the list?

With the ``in`` operator you have an implicit loop over the list.

  if 'readme.txt' in leafnames:
  print 'Hurray!'

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython before MainLoop

2007-08-15 Thread Chris Mellon
On 8/15/07, samwyse <[EMAIL PROTECTED]> wrote:
> Chris Mellon wrote:
> > On 8/9/07, Heikki Toivonen <[EMAIL PROTECTED]> wrote:
> >
> >>[david] wrote:
> >>
> >>>I'd like to refresh the display before I start the main loop.
>
> If your window isn't able to interact with the user, then I'd consider
> it a splash screen, no matter if it does look exactly like your main
> application interface.
>
> >>We have this kind of situation in Chandler, where we display and update
> >>the splash screen before we enter MainLoop.
> >>
> [...]
> >>3. The splash screen refresh is basically: draw new stuff,
> >>self.Layout(), self.Update(), wx.Yield()
> >>http://lxr.osafoundation.org/source/chandler/application/Application.py#1421
>
> Looking at the Chandler code suggests a solution to [david]'s original
> problem.  It is possible that, on Windows only, he may need to call
> Update to finish painting the display.
>
> 1432 self.Layout()
> 1433 if wx.Platform == '__WXMSW__':
> 1434 self.Update()
> 1435 wx.GetApp().Yield(True)
>
> > wxYield spins the event loop in place. This can have some serious
> > consequences if you aren't very careful with your usage, like
> > recursively entering event handlers. I generally consider it an
> > experts only interface, and avoid it.
>
> I'll confess to being one of those old-school programmers who, back in
> the day, wrote his code around big select loops instead of using
> threads, but I'm intriged by the "experts only" designation.  Can
> someone explain further?  Thanks!

The biggest problem is recursive events. You can end up entering an
event handler downstack from itself. There's other common problems -
event handlers are generally written to be short and sweet and not to
expect recursion and to complete without interruption. wxYield can
easily end up breaking that. Components that call wxYield are
especially dangerous. For example, some parts of wxWidgets call
wxYield internally. An event handler that aquired a lock was changed
to use one of those components and ended up deadlocking when it was
re-entered by the yield. I've also seen crashes when wxYield processed
a destroy event for a window in the middle of it's own event handler.

Because analyzing your event code to make sure it's reentrant is hard,
and is complicated even more by the fact that wxYield in a component
can cause problems far upstack in a caller, and because there is an
excellent alternative in the form of python generators, I avoid it's
usage from wxPython entirely.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What order does info get returned in by os.listdir()

2007-08-15 Thread Jeremy C B Nicoll
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:

> On Wed, 15 Aug 2007 12:34:27 +0100, Jeremy C B Nicoll wrote:
> 
> > I've some supplementary questions... my original code was looking at
> > each leafname in turn via
> > 
> >   for leaf in os.listdir(path):
> >   wholefile = os.path.join(path,leaf)
> >   if os.path.isfile(wholefile):
> >  if leaf.startswith("~"):
> > 
> > etc.  But I now realise I might alternatively do something like:
> > 
> >   leaflist = os.listdir(path)
> >   
> >   for leaf in leaflist:
> 
> But this is doing something different that the above code!?

I'm not sure if I understand you.  I know it's only "equivalent" to the
first line of what's above, ie iterate over a list of names, and obviously
it's got the sorting of that list done, but do you mean there's some other
difference?



> > How would I sort leaflist in a way that mimics the sort order that XP
> > shows me things under?
> 
> This depends on what XP is.  Which program?  Which locale?  How does the
> locale influence that programs sorting?

Well... XP is Windows XP (Pro as I think I said earlier), and I'm in the UK.
I explained earlier how XP shows me stuff in order when I tell it to sort by
name.  

> 
> > Secondly, my code is wasting time looking at subdirectories/files which
> > I already know I'm not interested in.  Is there a way to restrict
> > listdir to, say, only return info about subdirectories, or only about
> > dirs/files whose names match a pattern?
> 
> `os.listdir()` always returns all names.  You can or have to  filter the
> result if you are only interested in some of the names.  Simple pattern
> matching on names can be done with `glob.glob()`.
> 
> > Thirdly, once I've go a list of leafnames, somehow, is there a way to
> > ask Python if a specific leaf-value is in that list, without explicitly
> > looping through the items in the list?
> 
> With the ``in`` operator you have an implicit loop over the list.
> 
>   if 'readme.txt' in leafnames:
>   print 'Hurray!'

OK, that looks useful.  Thanks.

-- 
Jeremy C B Nicoll - my opinions are my own.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Combinatorial of elements in Python?

2007-08-15 Thread Sebastian Bassi
On 8/15/07, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote:
> Oh but it is:
> >>> ADictionary={"one":["A","B","C","D"],"two":["H","I"]}
> >>> result = set()
> >>> for one in ADictionary["one"]:
> ... for two in ADictionary["two"]:
> ... result.add(one + two)

That was easy :)
What about extending it for N elements inside the dictionary? Sounds
like a work for a recursive function.

-- 
Sebastián Bassi (セバスティアン)
Diplomado en Ciencia y Tecnología.
GPG Fingerprint: 9470 0980 620D ABFC BE63 A4A4 A3DE C97D 8422 D43D
-- 
http://mail.python.org/mailman/listinfo/python-list

Using python for dynamic behavior from C++

2007-08-15 Thread Jorgen Bodde
Hi all,

I am looking into using Python to introduce dynamic behavior in my
C++, e.g. something like a simulation where objects can interact with
eachother. I know Python can be called from C++, but is it possible to
call a binary compiled Python file / array from C++ ? The reason I ask
is that if my objects call a script every tick to do something, I
would not like to let the python interpreter recompile the same code
over and over again.

Any pointers to how I can do that?

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


Re: What order does info get returned in by os.listdir()

2007-08-15 Thread Jon Clements
To emulate the order of XP, you might be able to get away with
something like:-

sorted( myData, key=lambda L: L.replace('~',chr(0)) )

That just forces all '~'s to be before everything else.

hth,

Jon.

On 15 Aug, 14:33, Jeremy C B Nicoll <[EMAIL PROTECTED]> wrote:
> Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > On Wed, 15 Aug 2007 12:34:27 +0100, Jeremy C B Nicoll wrote:
>
> > > I've some supplementary questions... my original code was looking at
> > > each leafname in turn via
>
> > >   for leaf in os.listdir(path):
> > >   wholefile = os.path.join(path,leaf)
> > >   if os.path.isfile(wholefile):
> > >  if leaf.startswith("~"):
>
> > > etc.  But I now realise I might alternatively do something like:
>
> > >   leaflist = os.listdir(path)
> > >   
> > >   for leaf in leaflist:
>
> > But this is doing something different that the above code!?
>
> I'm not sure if I understand you.  I know it's only "equivalent" to the
> first line of what's above, ie iterate over a list of names, and obviously
> it's got the sorting of that list done, but do you mean there's some other
> difference?
>
> > > How would I sort leaflist in a way that mimics the sort order that XP
> > > shows me things under?
>
> > This depends on what XP is.  Which program?  Which locale?  How does the
> > locale influence that programs sorting?
>
> Well... XP is Windows XP (Pro as I think I said earlier), and I'm in the UK.
> I explained earlier how XP shows me stuff in order when I tell it to sort by
> name.  
>
>
>
>
>
>
>
> > > Secondly, my code is wasting time looking at subdirectories/files which
> > > I already know I'm not interested in.  Is there a way to restrict
> > > listdir to, say, only return info about subdirectories, or only about
> > > dirs/files whose names match a pattern?
>
> > `os.listdir()` always returns all names.  You can or have to  filter the
> > result if you are only interested in some of the names.  Simple pattern
> > matching on names can be done with `glob.glob()`.
>
> > > Thirdly, once I've go a list of leafnames, somehow, is there a way to
> > > ask Python if a specific leaf-value is in that list, without explicitly
> > > looping through the items in the list?
>
> > With the ``in`` operator you have an implicit loop over the list.
>
> >   if 'readme.txt' in leafnames:
> >   print 'Hurray!'
>
> OK, that looks useful.  Thanks.
>
> --
> Jeremy C B Nicoll - my opinions are my own.- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -


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


Re: make images with python

2007-08-15 Thread Boris Borcic
Lawrence Oluyede wrote:
> stefano <[EMAIL PROTECTED]> wrote:
>> I need make some images using python but i'm lost :P
> 
> 
> 

If you want to do antialiased drawings into images,
you might rather want to look for pil at

http://effbot.org/downloads/

and grab PIL together with the aggdraw extension
(while "core" PIL includes some drawing primitives,
last time I tried they weren't antialiased).

Best, BB

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


encrypting files + filestreams?

2007-08-15 Thread per9000
Hi python people,

I am trying to figure out the best way to encrypt files in python.

I've build a small script (see below) that encrypts the ubuntu 7.04
iso file in 2 minutes (I like python :) ).

But I have some thoughts about it. By pure luck (?) this file happened
to be N*512 bytes long so I do not have to add crap at the end - but
on files of the size N*512 + M (M != 521) I will add some crap to make
it fit in the algorithm. When I later decrypt I will have the stuff I
do not want. How do people solve this? (By writing the number of
relevant bytes in readable text in the beginning of the file?)

Also I wonder if this can be solved with filestreams (Are there
streams in python? The only python file streams I found in the evil
search engine was stuff in other forums.)


Other comments are of course also welcome,
Per


# crypto_hardcoded.py starts here

from Crypto.Cipher import AES

def encrypt2(cryptor, infile, outfile):
"""enly encrypt a few bytes at a time"""

size = 512
bytes = infile.read(size)

seek = 0
interval = 97
ctr = 0

while len(bytes) == size:
seek += size
if ctr % interval == 0:
print '\r%15d bytes completed' %  (seek),
ctr += 1

outfile.write(cryptor.encrypt(bytes))
# change to this to decrypt
# outfile.write(cryptor.decrypt(bytes))
bytes = infile.read(size)

if len(bytes) != 0:
bytes += "#" * (size - len(bytes))
outfile.write(cryptor.encrypt(bytes))
seek += len(bytes)

print '\r%15d bytes completed' %  (seek)

if __name__ == "__main__":
crptz = AES.new("my-secret_passwd")
ifile = file('/tmp/ubuntu-7.04-desktop-i386.iso','r')
ofile = file('/tmp/ubuntu-7.04-desktop-i386.iso.out','w')

encrypt2(crptz, ifile, ofile)
ifile.close()
ofile.close()

# crypto_hardcoded.py ends here

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


Re: Simple python iteration question

2007-08-15 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Shawn Milochik <[EMAIL PROTECTED]> wrote:
.
.
.
>Just for my own sanity: Isn't this the third response advocating the
>use of enumerate()? Did the other responses not get through, or was
>this a time-delay thing?
.
.
.
Yes.

Yes, for a variety of reasons, it's easy for it to happen that
all three-or-more enumerate-responders independently saw the
original question, but not any of their colleagues' responses.

Sometime we'll tell a few Usenet funnies about The Old Days
when transport included tape-backup-driven-by-private-car.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Retry: Question about FutureWarning

2007-08-15 Thread A.T.Hofkamp
On 2007-08-15, Paul McGuire <[EMAIL PROTECTED]> wrote:
> On Aug 14, 8:49 pm, Erik Max Francis <[EMAIL PROTECTED]> wrote:
>
> So if by '0x' you meant -1, then change this line to use -1.
> Otherwise, if you really meant 4294967295L, leave it at 0x and
> move on.

A third option is to specify 0x as 0xL in the latter case to
get rid of the warning.

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


Re: Using python for dynamic behavior from C++

2007-08-15 Thread A.T.Hofkamp
On 2007-08-15, Jorgen Bodde <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I am looking into using Python to introduce dynamic behavior in my
> C++, e.g. something like a simulation where objects can interact with
> eachother. I know Python can be called from C++, but is it possible to
> call a binary compiled Python file / array from C++ ? The reason I ask
> is that if my objects call a script every tick to do something, I
> would not like to let the python interpreter recompile the same code
> over and over again.
>
> Any pointers to how I can do that?

It is called 'embedding the Python Interpreter' and is in the second part of
the 'Extending and Embedding the Python Interpreter' document at python dot org.

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


Free Air Conditioners!!!!!

2007-08-15 Thread Lepi Duja
Air conditioning

http://airconditionerslinks.blogspot.com/

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


Re: What order does info get returned in by os.listdir()

2007-08-15 Thread Miles
On 8/15/07, Jeremy C B Nicoll wrote:
> Marc 'BlackJack' Rintsch wrote:
> > > How would I sort leaflist in a way that mimics the sort order that XP
> > > shows me things under?
> >
> > This depends on what XP is.  Which program?  Which locale?  How does the
> > locale influence that programs sorting?
>
> Well... XP is Windows XP (Pro as I think I said earlier), and I'm in the UK.
> I explained earlier how XP shows me stuff in order when I tell it to sort by
> name.

Case insensitive sort with ~ coming before all other characters:
some_list.sort(key=lambda k: k.lower().split("~"))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Retry: Question about FutureWarning

2007-08-15 Thread Steven W. Orr
Thanks guys, but that's not my question. The question is this: Why does 
the call to filterwarnings not work if it's placed inside the M1 module? 
Why do I have to place the call in M4 to make it work? This is more a 
question about how import works than it is about what the value of -1 is. 
;-)

On Tuesday, Aug 14th 2007 at 18:49 -0700, quoth Erik Max Francis:

=>Steven W. Orr wrote:
=>
=>> M1.py:268: FutureWarning: hex/oct constants > sys.maxint will
=>> return positive values in Python 2.4 and up
=>>StartTime   = safe_dict_get ( dic, 'starttime', 0x )
=>  ...
=>> import warnings
=>> warnings.filterwarnings('ignore', category=FutureWarning)
=>> 
=>> My question is this: Why can the warning not be shut off by putting the
=>> two lines in M1 where the reference exists to 0x ?
=>
=>You really don't want to shut off the warning; it means just what it says:
=>
=>Python 2.3.5 (#1, Feb  8 2005, 23:36:23)
=>[GCC 3.2.3] on linux2
=>Type "help", "copyright", "credits" or "license" for more information.
=> >>> 0x
=>:1: FutureWarning: hex/oct constants > sys.maxint will return 
=>positive values in Python 2.4 and up
=>-1
=>
=>Python 2.4.3 (#1, Mar 29 2006, 17:16:11)
=>[GCC 3.2.3] on linux2
=>Type "help", "copyright", "credits" or "license" for more information.
=> >>> 0x
=>4294967295L
=>

On Wednesday, Aug 15th 2007 at 06:10 -0700, quoth Paul McGuire:

=>On Aug 14, 8:49 pm, Erik Max Francis <[EMAIL PROTECTED]> wrote:
=>
=>So if by '0x' you meant -1, then change this line to use -1.
=>Otherwise, if you really meant 4294967295L, leave it at 0x and
=>move on.
=>
=>-- Paul
=>
=>-- 
=>http://mail.python.org/mailman/listinfo/python-list
=>

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Free Air Conditioners!!!!!

2007-08-15 Thread Paul Heslop
Lepi Duja wrote:
> 
> Air conditioning
> 
posting this crap under different names doesn't make it any more on
topic or make it any more likely we'll follow the link

-- 
Paul  (We won't die of devotion)  
---   
Stop and Look 
http://www.geocities.com/dreamst8me/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using python for dynamic behavior from C++

2007-08-15 Thread [EMAIL PROTECTED]
On Aug 15, 8:35 am, "Jorgen Bodde" <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I am looking into using Python to introduce dynamic behavior in my
> C++, e.g. something like a simulation where objects can interact with
> eachother. I know Python can be called from C++, but is it possible to
> call a binary compiled Python file / array from C++ ? The reason I ask
> is that if my objects call a script every tick to do something, I
> would not like to let the python interpreter recompile the same code
> over and over again.
>
> Any pointers to how I can do that?
>
> Regards,
> - Jorgen

Someone has already mentioned the documentation (http://
docs.python.org/ext/ext.html).  But in a nutshell, your code is not
`recompiled` everytime you send it to the interpreter.  Assuming you
put your code into a module, you'll do things that look a lot like
python, but only C -- for instance you'll actually import your python
module with the C function PyImport_Import.

After dancing with the guts of python for a bit, you'll really
appreciate all the magic that goes on under the hood when you type
python.  I know I did!

There are also tools to help extend python.  I like swig. (http://
www.swig.org/).  You're embedding, but hopefully you'll wise up and
realize it's better to write your app in python and drop to C when you
absolutely, positively need speed ;).

jw

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


Re: [Tutor] Python Book Recommendations

2007-08-15 Thread Shawn Milochik
If I could have only one book, I would buy "Core Python, Second
Edition," by Wesley Chun.

For the record, I own:
Core Python, Second Edition (great)
wxPython in Action (haven't used yet)
Beginning Python (barely used)
Python in a Nutshell (use as a reference, although interactive python
dir() is more useful)
Dive into Python (great book)
Python Cookbook (great book)
Python Pocket Reference (not very useful)
Python Phrasebook (I love the Phrasebook series, but this isn't a
necessary book)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ming on win32 anyone ? [help a noob]

2007-08-15 Thread [EMAIL PROTECTED]
On Aug 15, 8:03 am, "daz.diamond" <[EMAIL PROTECTED]> wrote:
> hoping someone can help ...
>
> how do I install ming (with python) on win32? have downloaded the tar.gz
> of ming-0.3.0 which doesn't have a handy self-installer, and I'm
> absolutely foxed as to what to do next ... the install instructions in
> the package seem to be linux oriented, which to me may as well be in greek
>
> any clues much appreciated, thx
>
> daz

I don't know what you've downloaded, but it does not sound like the
right thing, err ming.  The installer found here is 5.1.3.
http://sourceforge.net/project/showfiles.php?group_id=2435

Maybe you should consider cygwin?

jw

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


Re: FM synthesis using Numpy

2007-08-15 Thread Bas
You got your math wrong. What you are calculating is:
sin(2*pi*(1000+15*sin(2*pi*6*t))*t) = sin(2*pi*1000*t +
2*pi*15*sin(2*pi*6*t)*t)
The 'instantaneous frequency' can be calculated by differentiating the
argument of the sine and dividing by 2pi:
x = sin(phi(t)) -> f_inst = d (phi(t)) / dt / (2*pi)
So in your case:
f_inst = 1000 + 15*sin(2*pi*6*t) + 2*pi*t*6*15*cos(2*pi*6*t)
the last term explains the effect you hear.

What you want is:
f_inst = f0 + df*cos(2*pi*fm*t)
Integrating this and multiplying by 2pi gives the phase:
phi(t) = 2*pi*f0*t + sin(2*pi*fm*t)*df/fm

So you can achieve the frequency modulation by using phase modulation
(these two are related). You can do this with your own code by

phi = oscillator(t, freq=6, amp=15/6)
tone = oscillator(t, freq=1000, amp=0.1, phase=phi)

cheers,
Bas

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


Re: ming on win32 anyone ? [help a noob]

2007-08-15 Thread kyosohma
On Aug 15, 9:46 am, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> On Aug 15, 8:03 am, "daz.diamond" <[EMAIL PROTECTED]> wrote:
>
> > hoping someone can help ...
>
> > how do I install ming (with python) on win32? have downloaded the tar.gz
> > of ming-0.3.0 which doesn't have a handy self-installer, and I'm
> > absolutely foxed as to what to do next ... the install instructions in
> > the package seem to be linux oriented, which to me may as well be in greek
>
> > any clues much appreciated, thx
>
> > daz
>
> I don't know what you've downloaded, but it does not sound like the
> right thing, err ming.  The installer found here is 
> 5.1.3.http://sourceforge.net/project/showfiles.php?group_id=2435
>
> Maybe you should consider cygwin?
>
> jw

I think the OP is referring to this: http://ming.sourceforge.net/

If so, it looks like it needs manual compilation using a C/C++
compiler of some sort.

Mike

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


Re: Combinatorial of elements in Python?

2007-08-15 Thread Thomas Nelson
On Aug 15, 8:39 am, "Sebastian Bassi" <[EMAIL PROTECTED]>
wrote:
> That was easy :)
> What about extending it for N elements inside the dictionary? Sounds
> like a work for a recursive function.

Here's my attempt:
[code]
def backtrack(groups,position=0, answer=''):
if position==len(groups):
yield answer
else:
for e in groups[position]:
for x in backtrack(groups,position+1,answer+e):
yield x


groups = [
['a','b','c'],
['w','x','y','z'],
['1','2']]


for i in backtrack(groups):
print i
[/code]

If you need to put the result into a set, you can.  As for the
original question "Is there a builtin function for this", what you're
asking is essentially the standard recursive backtracking algorithm.
In your case, each "layer" in the network is fully connected to the
network below it, much the way layers in a neural network are set up.
Sadly, there isn't a graph/network algorithm module in the python
standard library.  There are graph-algorithm type libraries out there
I think, but I've never used any of them, so I can't be much help.

-Tom

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


Re: Opinions about this new Python book?

2007-08-15 Thread kyosohma
On Aug 14, 1:43 pm, [EMAIL PROTECTED] wrote:
> On Aug 14, 12:46 pm, "Shawn Milochik" <[EMAIL PROTECTED]> wrote:
>
>
>
> > Yes, please post back to the list. I saw this book on Amazon, but
> > there's no table of contents listed, nor is there one on the
> > publisher's site.
>
> > Thanks,
> > Shawn
>
> > On 8/14/07, James Matthews <[EMAIL PROTECTED]> wrote:
>
> > > i got to say that the best python book i bought was Core Python 
> > > Programming
> > > (2nd)  by Wesly Chun! Aside for all the spelling mistakes and syntax 
> > > errors
> > > that there are i feel that the book really explained the language well for
> > > someone coming from another programming language!
>
> > > On 8/14/07, Dick Moores <[EMAIL PROTECTED]> wrote:
> > > > At 05:57 AM 8/14/2007, [EMAIL PROTECTED] wrote:
> > > > >On Aug 14, 7:05 am, Dick Moores <[EMAIL PROTECTED]> wrote:
> > > > > > I'd appreciate opinions about this new Python book.
>
> > > > > > Title: Python Power!: The Comprehensive Guide
> > > > > > Author:  Matt Telles
> > > > > > Publisher:  Course Technology
> > > > > > Pub. Date:  Jul 27, 2007
> > > > > > Edition:  1st edition
> > > > > > Binding:  Paperback
> > > > > > Pages:  508
> > > > > > ISBN:  1598631586
> > > > > > List Price:  34.99 USD
>
> > > > > > The book on the publisher's website: 
>
> > > > > > And at BestBookDeal.com:
> > > > > > 
>
> > > > > > Thanks,
>
> > > > > > Dick Moores
>
> > > > >I just got this book over the weekend. I'll start reading/skimming
> > > > >through it this week and hopefully remember to get back to you.
>
> > > > Thanks!
>
> > > > >  By the
> > > > >way, why do you want to know?
>
> > > > If the experts like it, I'll buy it.
>
> > > > Dick
>
> > > > --
> > > >http://mail.python.org/mailman/listinfo/python-list
>
> > > --
> > >http://www.goldwatches.com/
> > >http://www.jewelerslounge.com
> > > --
> > >http://mail.python.org/mailman/listinfo/python-list
>
> > --
> > Please read:http://milocast.com/2007/07/31/this-i-believe/
>
> Here's an abbreviated Table of Contents...just chapter titles. The
> book's table of contents also lists section headers.
>
> Chapter 1: About Python
> Chapter 2: Python Language Overview
> Chapter 3: Tools
> Chapter 4: Data Types
> Chapter 5: Control Flow
> Chapter 6: Input & Output
> Chapter 7: Functions & Modules
> Chapter 8: Exception Handling
> Chapter 9: Object-Oriented Programming
> Chapter 10: Classes and Objects in Python
> Chapter 11: The Python Library
> Chapter 12: The GUI - Tkinter
> Chapter 13: The Web Server - Apache
> Chapter 14: Working with Databases
> Chapter 15: Putting It All Together
> Chapter 16: Python and Graphics
>
> Mike

More on the subject...the writer is very conversational in tone and it
makes for a light read in the first 1 1/2 chapters that I've
completed. I've noticed a couple of sentence errors, but nothing in
the code.

He disses lambdas, which I haven't used for anything either. But I
have seen good uses for them (particularly in Tkinter callbacks),
although they don't seem to be as readable or usable as the rest of
Python. For some reason, the author makes the claim that the term
"Predicate" is "bandied about quite a bit in the literature" of
Python. I have 17 or so Python books and I don't think I've ever seen
this used in conjunction with Python...or in any of the docs I've
skimmed. What the!?

I'll keep you'all posted.

Mike

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


Python, Sharepoint, .NET, NTLM

2007-08-15 Thread frikk
Hey everyone,
  I need to authenticate with a Sharepoint server. It looks to be
using 'NTLM' authentication.  I've looked on the newsgroup and it
looks like there has been talk of using python and NTLM but no
definite solutions are apparent.

  Can anyone provide me with any kind of help on this issue? URLLIB2
keeps getting a 401 error when I try any kind of authentication.

I am trying to use python here in my company (for obvious reasons -
python is awesome!) and this is the first major project that would use
it.  Unfortunately if I cannot talk to Sharepoint (I am just trying to
get a list of .xml files and data from a form library) I cannot use
python.


 The other solution would be: Does anyone know how to get xml files
from a sharepoint library in python?  The worst case would be using
another language to compile just the xml file downloader.  This is not
the optimal solution.

Thank you,
Blaine

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


Re: Memory leak when creating lots of object

2007-08-15 Thread Paul Moore
On 14 Aug, 05:57, Godzilla <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I have a program that create and pop an object off a queue, but it is
> experiencing some memory leakage. I have been unable to detect where
> the memory leakage occur. The strange thing is when i replace the
> object creation with a plain integer/string, the leak goes away...
> Here's the code I used as my test:
[...]
> I can see the memory usage increases slowly in Task Manager under XP,
> but do not know why. Anyone help?

I tried your code on my (Windows XP SP2, Python 2.5) system. No memory
leak here - I left it running for over 5 minutes and memory usage was
static at just under 4MB.

Do you see memory growth with precisely this code? Over what period?
How much?

Paul.

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


Re: Python Book Recommendations

2007-08-15 Thread Azazello
On Aug 15, 7:47 am, "Shawn Milochik" <[EMAIL PROTECTED]> wrote:
> If I could have only one book, I would buy "Core Python, Second
> Edition," by Wesley Chun.
>
> For the record, I own:
> Core Python, Second Edition (great)
> wxPython in Action (haven't used yet)
> Beginning Python (barely used)
> Python in a Nutshell (use as a reference, although interactive python
> dir() is more useful)
> Dive into Python (great book)
> Python Cookbook (great book)
> Python Pocket Reference (not very useful)
> Python Phrasebook (I love the Phrasebook series, but this isn't a
> necessary book)

I would like to add:

Foundations of Python Network Programming

I also use the Python Essential Reference.  (although all of the
information is probably online it's nice to have a solid paper
reference)

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


Re: Python Book Recommendations

2007-08-15 Thread kyosohma
On Aug 15, 10:30 am, Azazello <[EMAIL PROTECTED]> wrote:
> On Aug 15, 7:47 am, "Shawn Milochik" <[EMAIL PROTECTED]> wrote:
>
> > If I could have only one book, I would buy "Core Python, Second
> > Edition," by Wesley Chun.
>
> > For the record, I own:
> > Core Python, Second Edition (great)
> > wxPython in Action (haven't used yet)
> > Beginning Python (barely used)
> > Python in a Nutshell (use as a reference, although interactive python
> > dir() is more useful)
> > Dive into Python (great book)
> > Python Cookbook (great book)
> > Python Pocket Reference (not very useful)
> > Python Phrasebook (I love the Phrasebook series, but this isn't a
> > necessary book)
>
> I would like to add:
>
> Foundations of Python Network Programming
>
> I also use the Python Essential Reference.  (although all of the
> information is probably online it's nice to have a solid paper
> reference)

Depending on what you're doing, a book can actually be faster than
Google! Of course, a lot of these books don't cover any 3rd party
modules, so Google is still very handy.

Mike

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


closing StringIO objects

2007-08-15 Thread Neil Cerutti
The documentation says the following about StringIO.close:

  close( ) 
  Free the memory buffer. 

Or else... what? 

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


Re: Opinions about this new Python book?

2007-08-15 Thread Neil Cerutti
On 2007-08-15, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> For some reason, the author makes the claim that the term
> "Predicate" is "bandied about quite a bit in the literature" of
> Python. I have 17 or so Python books and I don't think I've
> ever seen this used in conjunction with Python...or in any of
> the docs I've skimmed. What the!?

The document searching facility reveals that the term is bandied
about in five places in the standard documentation. These uses
seem approriate and uncontroversial to me.

These document functions accepting predicates as aruments:

6.5.1 Itertools functions
6.5.3 Recipes
11.47 Creating a new Distutils command
26.10.1 Types and members

The following provides a few predicate functions (weird! I'd have
never thought to look there for, e.g., ismodule):

6.7 operator -- Standard operators as functions

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


Re: Python, Sharepoint, .NET, NTLM

2007-08-15 Thread kyosohma
On Aug 15, 10:11 am, frikk <[EMAIL PROTECTED]> wrote:
> Hey everyone,
>   I need to authenticate with a Sharepoint server. It looks to be
> using 'NTLM' authentication.  I've looked on the newsgroup and it
> looks like there has been talk of using python and NTLM but no
> definite solutions are apparent.
>
>   Can anyone provide me with any kind of help on this issue? URLLIB2
> keeps getting a 401 error when I try any kind of authentication.
>
> I am trying to use python here in my company (for obvious reasons -
> python is awesome!) and this is the first major project that would use
> it.  Unfortunately if I cannot talk to Sharepoint (I am just trying to
> get a list of .xml files and data from a form library) I cannot use
> python.
>
>  The other solution would be: Does anyone know how to get xml files
> from a sharepoint library in python?  The worst case would be using
> another language to compile just the xml file downloader.  This is not
> the optimal solution.
>
> Thank you,
> Blaine

NTLM is mentioned here: http://ntlmaps.sourceforge.net/

Others have pointed to Iron Python for this sort of thing. I would
think that you could use COM.

Here's a link that uses Iron Python: 
http://blog.glenc.net/2007/08/12/sharepoint-meet-python/

Finally, it looks like someone wrote some kind interface:
http://sourceforge.net/projects/pysharepoint

Hope that helps!

Mike

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


Re: closing StringIO objects

2007-08-15 Thread Alex Martelli
Neil Cerutti <[EMAIL PROTECTED]> wrote:

> The documentation says the following about StringIO.close:
> 
>   close( ) 
>   Free the memory buffer. 
> 
> Or else... what? 

Or else the memory buffer sticks around, so you can keep calling
getvalue as needed.  I believe the freeing will happen anyway,
eventually, if and when the StringIO instance is garbage collected (just
like, say, a file object's underlying fd gets closed when the file
object is garbage collected), but relying on such behavior is often
considered a dubious practice nowadays (given the existence of many
Python implementations whose GC strategies differ).


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


sub-classing the types in the builtin module datetime

2007-08-15 Thread Colin J. Williams
I wish to sub-class (if that's the right word) datetime and to use a 
different signature for the constructor.

The second part has gone smoothly, but it is difficult to access the 
type's methods from the sub-class instance.

I'm beginning to wonder whether it might might be simpler to write my 
own Date class.

Does anyone have any comments please?

Colin W.

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


Re: Simple python iteration question

2007-08-15 Thread BartlebyScrivener
On Aug 14, 11:59 am, "Shawn Milochik" <[EMAIL PROTECTED]> wrote:

> Just for my own sanity: Isn't this the third response advocating the
> use of enumerate()? Did the other responses not get through, or was
> this a time-delay thing?
>
> Thanks,
> Shawn

Look at the timestamps.  All within ten minutes. And those ten minutes
are spent keyboarding your response in and posting, plus it takes
several minutes for the posts to appear on Google Groups.

rd


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


Re: moving files in a seperate thread (and/or with progress?)

2007-08-15 Thread kyosohma
On Aug 15, 4:28 am, "Jorgen Bodde" <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I want to make a small batch copy tool that scans for certain files,
> and copies them to a specified directory. Since the files are huge
> (AVI / DIVX) typical 300 to 700 Mb, I want to provide the user with
> some feedback during the file copy.
>
> Here is my dillemma; When I use shutil.move(..,..) I have to wait
> until it's done, there is no feedback, so the GUI basically hangs.
> However, shutil.move can be fast because it intelligently renames the
> file when it is on the same medium, but slow when it moves to a
> different one.
> When I use my own implementation of a move mechanism that provides
> feedback, I lose that intelligence, and I might slow down the copy
> process unneccessarily.
>
> When I move files, feedback is handy to have, but not neccesary so I
> thought I can also call shutil.move from a seperate thread so the main
> GUI stays responsive. What are my options in aborting a move by
> killing the thread or are there other (3rdparty) modules I might use
> to get better move or copy performances?
>
> Just opening the file, performing a block copy myself seems like it
> will slow down the transfer, but up until now I found no way to move
> or copy with progress or abilities to abort the file transfer..
>
> Any ideas?
>
> Regards,
> - Jorgen

What GUI toolkit are you using? I know that wxPython has a status
widget that could be updated in a thread and it has some good examples
of using threads with long running tasks. I created a program with it
that deletes folders and updates me on its progress.

You can see the wxPython implementation here: 
http://wiki.wxpython.org/LongRunningTasks

Their widget is called a ProgressDialog. I think there's a custom one
too...

Mike

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


Re: Opinions about this new Python book?

2007-08-15 Thread Alex Martelli
Neil Cerutti <[EMAIL PROTECTED]> wrote:

> On 2007-08-15, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > For some reason, the author makes the claim that the term
> > "Predicate" is "bandied about quite a bit in the literature" of
> > Python. I have 17 or so Python books and I don't think I've
> > ever seen this used in conjunction with Python...or in any of
> > the docs I've skimmed. What the!?
> 
> The document searching facility reveals that the term is bandied
> about in five places in the standard documentation. These uses
> seem approriate and uncontroversial to me.
> 
> These document functions accepting predicates as aruments:
> 
> 6.5.1 Itertools functions
> 6.5.3 Recipes
> 11.47 Creating a new Distutils command
> 26.10.1 Types and members
> 
> The following provides a few predicate functions (weird! I'd have
> never thought to look there for, e.g., ismodule):
> 
> 6.7 operator -- Standard operators as functions

Module inspect also provides useful predicates (though I don't remember
if its docs CALL them predicates;-).


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


Re: closing StringIO objects

2007-08-15 Thread Neil Cerutti
On 2007-08-15, Alex Martelli <[EMAIL PROTECTED]> wrote:
> Neil Cerutti <[EMAIL PROTECTED]> wrote:
>> The documentation says the following about StringIO.close:
>> 
>>   close( ) 
>>   Free the memory buffer. 
>> 
>> Or else... what? 
>
> Or else the memory buffer sticks around, so you can keep
> calling getvalue as needed.  I believe the freeing will happen
> anyway, eventually, if and when the StringIO instance is
> garbage collected (just like, say, a file object's underlying
> fd gets closed when the file object is garbage collected), but
> relying on such behavior is often considered a dubious practice
> nowadays (given the existence of many Python implementations
> whose GC strategies differ).

Thanks. It doesn't seem worth the trouble, given your
explanation.

I was refactoring some pickled StringIO code, and decided to try
out the with statement. I discovered that StringIO isn't a
context manager, so I dipped into contextlib and found 'closing'.
But it's starting to look overengineered, and I realized I had no
idea if it was worth all this fuss just to close a StringIO
object.

from __future__ import with_statement
from contextlib import closing
import pickle
import StringIO

def unserialize(d):
with closing(StringIO.StringIO(d)) as s:
obj = pickle.load(s)
return obj

def serialize(d):
with closing(StringIO.StringIO()) as s:
pickle.dump(d, s)
arg = s.getvalue()
return arg

-- 
Neil Cerutti
Beethoven wrote fewer symphonies than Haydn and Mozart because he wrote
longer, and besides he went death. --Music Lit Essay
-- 
http://mail.python.org/mailman/listinfo/python-list


All names in the current module

2007-08-15 Thread Torsten Bronger
Hallöchen!

How can I get a list with all classes defined in the current module?
Thank you!

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
  (See http://ime.webhop.org for ICQ, MSN, etc.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Book Recommendations

2007-08-15 Thread vasudevram
On Aug 15, 8:34 pm, [EMAIL PROTECTED] wrote:
> On Aug 15, 10:30 am, Azazello <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Aug 15, 7:47 am, "Shawn Milochik" <[EMAIL PROTECTED]> wrote:
>
> > > If I could have only one book, I would buy "Core Python, Second
> > > Edition," by Wesley Chun.
>
> > > For the record, I own:
> > > Core Python, Second Edition (great)
> > > wxPython in Action (haven't used yet)
> > > Beginning Python (barely used)
> > > Python in a Nutshell (use as a reference, although interactive python
> > > dir() is more useful)
> > > Dive into Python (great book)
> > > Python Cookbook (great book)
> > > Python Pocket Reference (not very useful)
> > > Python Phrasebook (I love the Phrasebook series, but this isn't a
> > > necessary book)
>
> > I would like to add:
>
> > Foundations of Python Network Programming
>
> > I also use the Python Essential Reference.  (although all of the
> > information is probably online it's nice to have a solid paper
> > reference)
>
> Depending on what you're doing, a book can actually be faster than
> Google! Of course, a lot of these books don't cover any 3rd party
> modules, so Google is still very handy.
>
> Mike

I second some of those recommendations - for the books I own / have
read:

Python Cookbook - excellent
Python in a Nutshell - excellent

Though interactive dir() is good, it doesn't give you a lot of things
that Python in a Nutshell and the official Python docs do - rules of
the language, info on new-style classes, etc. Also, Google for "Guide
to Python Introspection" - a good online article that shows a lot more
about that topic, over and above use of dir().

Also: Programming Python - excellent.

Didn't know about the Python Network programming book - thanks, will
check it out.

Vasudev Ram
http://www.dancingbison.com
http://jugad.livejournal.com
http://sourceforge.net/projects/xtopdf


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


Re: Guitar Reviews

2007-08-15 Thread Steve Holden
Dustan wrote:
> On Aug 15, 7:32 am, [EMAIL PROTECTED] wrote:
> 
> 
 op.mother.speak()
> Congratulations! You've just given your email address to millions of
> people across Usenet!
> What do you have to say for yourself?

Probably something along the lines of "that's OK, it's disposable so I 
don't care who knows it".

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: ctypes windll question

2007-08-15 Thread sturlamolden
On Aug 14, 11:45 am, Tzury <[EMAIL PROTECTED]> wrote:

> I followed the tutorial about ctypes and I still cannot figure out how
> to call a method of a calss within the dll.

ctypes interfaces with C, not C++. C++ compilers do various forms of
name manging, create virtual tables, etc. that are compiler dependent.
You cannot call C++ from ctypes.






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


Re: Simple python iteration question

2007-08-15 Thread Gabriel Genellina
En Wed, 15 Aug 2007 10:37:16 -0300, Cameron Laird <[EMAIL PROTECTED]>  
escribi�:

> Shawn Milochik <[EMAIL PROTECTED]> wrote:
>> Just for my own sanity: Isn't this the third response advocating the
>> use of enumerate()? Did the other responses not get through, or was
>> this a time-delay thing?
>Yes, for a variety of reasons, it's easy for it to happen that
> all three-or-more enumerate-responders independently saw the
> original question, but not any of their colleagues' responses.
>
> Sometime we'll tell a few Usenet funnies about The Old Days
> when transport included tape-backup-driven-by-private-car.

"Never underestimate the bandwidth of a station wagon full of tapes  
hurtling down the highway"
(Andrew S. Tanenbaum, Computer Networks, 1996; maybe the origin is much  
older)

-- 
Gabriel Genellina

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

how to convert a c program to java program

2007-08-15 Thread Fred Shu (fshu)
I heard I need to port C program to JPython first and compile it to
native JAVA.  I don't know
anything about JPython.  Is there a tool to do the porting?  If not,
what is the quickest way to learn
JPython?
 
Thanks,
Fred
-- 
http://mail.python.org/mailman/listinfo/python-list

Move files/directories to Recycle Bin using standard Python libs

2007-08-15 Thread Kevin D.Smith
I would like to move files and directories to the Recycle Bin on 
Windows from Python.  I have found some older articles describing how 
to do this, but they require additional packages to be installed.  I'm 
working on a plugin for an existing project and only have the standard 
library to work with.  Is there a way to use the Recycle Bin using 
standard Python?

-- 
Kevin D. Smith

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


Re: Combinatorial of elements in Python?

2007-08-15 Thread Mikael Olofsson


Sebastian Bassi wrote:
> Hello, could you do it for an indefinite number of elements? You did
> it for a fixed (2) number of elements. I wonder if this could be done
> for all members in a dictionary.

What is unclear here is in what order the keys should be visited. The 
following assumes that the keys should be considered in alphanumeric order.

 >>> def combine(d):
if not d:
return []
elif len(d)==1:
return d.values()[0]
else:
keys = d.keys()
keys.sort()
leftKeys = keys[0:len(keys)//2]
rightKeys = keys[len(keys)//2:]
leftDict = dict((key,d[key]) for key in leftKeys)
rightDict = dict((key,d[key]) for key in rightKeys)
return [x+y for x in combine(leftDict) for y in combine(rightDict)]

   
 >>> 
A={'field1':['a','A'],'field2':['b','B'],'field3':['c','C'],'field4':['d','D']}
 >>> combine(A)
['abcd', 'abcD', 'abCd', 'abCD', 'aBcd', 'aBcD', 'aBCd', 'aBCD', 'Abcd', 
'AbcD', 'AbCd', 'AbCD', 'ABcd', 'ABcD', 'ABCd', 'ABCD']


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


Re: All names in the current module

2007-08-15 Thread Lawrence Oluyede
Torsten Bronger <[EMAIL PROTECTED]> wrote:
> How can I get a list with all classes defined in the current module?
> Thank you!

[EMAIL PROTECTED] ~ % cat > t.py
class A: pass

[EMAIL PROTECTED] ~ % python
Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04) 
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import t
>>> print dir(t)
['A', '__builtins__', '__doc__', '__file__', '__name__']

Now you have the list of names. To find out if they are actual classes
or not you can do this:

>>> import inspect
>>> for member in dir(t):
... print member, inspect.isclass(getattr(t, member))
... 
A True
__builtins__ False
__doc__ False
__file__ False
__name__ False

HTH

-- 
Lawrence, oluyede.org - neropercaso.it
"It is difficult to get a man to understand 
something when his salary depends on not
understanding it" - Upton Sinclair
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Combinatorial of elements in Python?

2007-08-15 Thread Sebastian Bassi
On 8/15/07, Mikael Olofsson <[EMAIL PROTECTED]> wrote:
> What is unclear here is in what order the keys should be visited. The
> following assumes that the keys should be considered in alphanumeric order.

Yes, my fault. The orden should be given by a string, like:

DCDBA
Using this dictionay.
A={'A':['1','2'],'B':['4','5'],'C':['6','7','8'],'D':['9']}

Should return:

'96941'
'97941'
'97942'
'96942'
'98941'
'98942'
'96951'
'97951'
'97952'
'96952'
'98951'
'98952'



-- 
Sebastián Bassi (セバスティアン)
Diplomado en Ciencia y Tecnología.
GPG Fingerprint: 9470 0980 620D ABFC BE63 A4A4 A3DE C97D 8422 D43D
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: ming on win32 anyone ? [help a noob]

2007-08-15 Thread Thomas Heller
daz.diamond schrieb:
> hoping someone can help ...
> 
> how do I install ming (with python) on win32? have downloaded the
> tar.gz of ming-0.3.0 which doesn't have a handy self-installer, and
> I'm absolutely foxed as to what to do next ... the install
> instructions in the package seem to be linux oriented, which to me
> may as well be in greek
> 
> any clues much appreciated, thx
> 
> daz

Maybe you want this one:

http://www.develer.com/oss/GccWinBinaries

Quote from that page:

"""
Unofficial MinGW GCC binaries for Windows

This page contains a friendly installer for GCC 4.1.2 for Windows (native 
"mingw" win32 version).
It's an unofficial release, not promoted by the MinGW project. It features full 
Python integration.
"""

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


Importing DLLs

2007-08-15 Thread Corbitt, Kyle
I'm running Linux with Python 2.3.  I have a C shared object file (*.so) and I 
need to be able to call its functions from within Python.  I have found a 
couple of Python modules that allow me to do this (dl, ctypes) but 
unfortunately I am only able to get them to return integers, even for function 
calls that I KNOW the library is supposed to return other types for.  I need 
the library to be able to return doubles, 2D arrays and hopefully strings as 
well.  I do have access to the C source code that the library was compiled from 
and can change it if necessary but I know even less about C than I do about 
Python so it'd be great if I could avoid that.
 
Keep in mind that I am a python newbie (I only have a few weeks' experience) so 
the more detailed you can make your response, the better.  Example code would 
be great.  I'm sure there's a way to do this but I've been  bashing my head 
against this problem for a couple days now and haven't made much progress.
 
Thanks,
Kyle
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python Book Recommendations

2007-08-15 Thread Beliavsky
On Aug 15, 10:47 am, "Shawn Milochik" <[EMAIL PROTECTED]> wrote:
> If I could have only one book, I would buy "Core Python, Second
> Edition," by Wesley Chun.

I have bought about half a dozen Python books but will purchase only
Python 3 books in the future, when they become available. I wonder
when that will be and if most of the current books will be revised to
conform to Python 3.

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


Re: Move files/directories to Recycle Bin using standard Python libs

2007-08-15 Thread kyosohma
On Aug 15, 11:39 am, Kevin D. Smith <[EMAIL PROTECTED]> wrote:
> I would like to move files and directories to the Recycle Bin on
> Windows from Python.  I have found some older articles describing how
> to do this, but they require additional packages to be installed.  I'm
> working on a plugin for an existing project and only have the standard
> library to work with.  Is there a way to use the Recycle Bin using
> standard Python?
>
> --
> Kevin D. Smith

Sounds like a Windows only thing to me, so you'll probably have to use
the win32 package regardless. See the following links:

http://mail.python.org/pipermail/python-list/2004-October/287638.html
http://tgolden.sc.sabren.com/python/win32_how_do_i/copy-a-file.html

Mike

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


"Variable variable name" or "variable lvalue"

2007-08-15 Thread mfglinux
Hello to everybody

I would like to know how to declare in python a "variable name" that
it is in turn a variable
In bash shell I would wrote sthg like:

for x in `seq 1 3`
do
  M$i=Material(x)  #Material is a python class
done

Why I need this? Cause I have a python module that obliges me to build
a variable called Period, which should have a variable name of
summands (depends on the value of x)

#Let's say x=3, then Period definition is
Period=Slab(Material1(12.5)+Material2(25)+Material3(12.5)) #Slab is a
python class

I dont know how to automatize last piece of code for any x

thank you

Marcos

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


Re: sub-classing the types in the builtin module datetime

2007-08-15 Thread Michael Amrhein
Colin J. Williams wrote:
> I wish to sub-class (if that's the right word) datetime and to use a 
> different signature for the constructor.
> 
> The second part has gone smoothly, but it is difficult to access the 
> type's methods from the sub-class instance.
> 
What's difficult?
 >>> from datetime import datetime
 >>> class mydt(datetime): pass
...
 >>> dt=mydt(2007,8,15)
 >>> dt.day
15
 >>> dt.now()
mydt(2007, 8, 15, 18, 57, 58, 562000)

How did you overwrite the constuctor?
Are you sure your constructor really returns a subclass of datetime?

> I'm beginning to wonder whether it might might be simpler to write my 
> own Date class.
> 
If you only want to change the signature of the constuctor, just write a 
factory function.

> Does anyone have any comments please?
> 
> Colin W.
> 

Have fun,
Michael
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sub-classing the types in the builtin module datetime

2007-08-15 Thread Jay Loden
Colin J. Williams wrote:
> I wish to sub-class (if that's the right word) datetime and to use a 
> different signature for the constructor.
> 
> The second part has gone smoothly, but it is difficult to access the 
> type's methods from the sub-class instance.
> 
> I'm beginning to wonder whether it might might be simpler to write my 
> own Date class.
> 
> Does anyone have any comments please?
> 
> Colin W.

I think it would be most effective if you can post the code you're using that 
illustrates the issue, and what you're trying to do so that the list members 
can analyze the actual problem. Tracebacks etc are also welcome if applicable.

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


Re: ming on win32 anyone ? [help a noob]

2007-08-15 Thread daz.diamond
[EMAIL PROTECTED] wrote:
> On Aug 15, 9:46 am, "[EMAIL PROTECTED]"
> <[EMAIL PROTECTED]> wrote:
>> On Aug 15, 8:03 am, "daz.diamond" <[EMAIL PROTECTED]> wrote:
>>
>>> hoping someone can help ...
>>> how do I install ming (with python) on win32? have downloaded the tar.gz
>>> of ming-0.3.0 which doesn't have a handy self-installer, and I'm
>>> absolutely foxed as to what to do next ... the install instructions in
>>> the package seem to be linux oriented, which to me may as well be in greek
>>> any clues much appreciated, thx
>>> daz
>> I don't know what you've downloaded, but it does not sound like the
>> right thing, err ming.  The installer found here is 
>> 5.1.3.http://sourceforge.net/project/showfiles.php?group_id=2435
>>
>> Maybe you should consider cygwin?
>>
>> jw
> 
> I think the OP is referring to this: http://ming.sourceforge.net/
> 
> If so, it looks like it needs manual compilation using a C/C++
> compiler of some sort.
> 
> Mike
> 

yup, ming as in the ability to make swf files ... got it running with 
php no problem, but python seems another story ...
manual compilation using c/c++ sounds complicated - is this the sort of 
thing i could do without knowledge of c/c++ or am i just barking at 
lamp-posts ?

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


Re: All names in the current module

2007-08-15 Thread Fabio Z Tessitore
Il Wed, 15 Aug 2007 19:01:17 +0200, Lawrence Oluyede ha scritto:

> Torsten Bronger <[EMAIL PROTECTED]> wrote:
>> How can I get a list with all classes defined in the current module?
>> Thank you!
> 
> [EMAIL PROTECTED] ~ % cat > t.py
> class A: pass
> 
> [EMAIL PROTECTED] ~ % python
> Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04) [GCC 4.0.1 (Apple
> Computer, Inc. build 5367)] on darwin Type "help", "copyright",
> "credits" or "license" for more information.
 import t
 print dir(t)
> ['A', '__builtins__', '__doc__', '__file__', '__name__']
> 
> Now you have the list of names. To find out if they are actual classes
> or not you can do this:


to get names' list you can simply call globals()

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


Re: Hijack! Different book: (was: Opinions about this new Python book?

2007-08-15 Thread kyosohma
On Aug 15, 12:52 pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Wed, 15 Aug 2007 08:32:30 -0700, [EMAIL PROTECTED] declaimed the
> following in comp.lang.python:
>
> > More on the subject...the writer is very conversational in tone and it
> > makes for a light read in the first 1 1/2 chapters that I've
> > completed. I've noticed a couple of sentence errors, but nothing in
> > the code.
>
> Hopefully it isn't quite as annoying as some of what I've found in
> the Turbogears book that recently arrived from Amazon. (Rapid Web
> Applications with TurboGears)
>
> I've so far found a couple of pages where editing rewrites of
> paragraphs left redundancies. Example -- section 4.3:
>
> second paragraph
>
> """
> ... We set up some variables, and then create a new /Bookmark/ object
> with the exact same syntax we used earlier in the chapter when we
> created our first bookmark through /tg-admin shell/.
> """
>
> sentence/sample code/next paragraph
>
> """
> This method sets up a few variables, and then creates a new /Bookmark/
> object using the exact same syntax we used earlier in the chapter when
> we created out first bookmark through /tg-admin shell/. ...
> """
>
> That's the most blatant, so far, but I've found a few other examples
> where a paragraph below a code sample basically restates the paragraph
> above it; and the paragraph above seems confusing because it reads as if
> it is commenting on prior material, not following material.
>
> It's as if the book had been first written using, say, "describe, show
> code", then edited by someone favoring "show code, explain" style... And
> the two versions were then merged by a third person... Hmmm, there are
> three authors...
>
> --
> WulfraedDennis Lee Bieber   KD6MOG
> [EMAIL PROTECTED] [EMAIL PROTECTED]
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff:   [EMAIL PROTECTED])
> HTTP://www.bestiaria.com/

I have this book, but I haven't read it. However, I think the user
reviews on Amazon complained quite a bit about the TurboGears book's
writing and how it was pretty lousy. Even the code was broken. I look
forward to seeing just how truly awful it is.

As for this book, "Python Power!", I haven't noticed anything like
what you describe. An example issue I've noticed is stuff like this
sentence:

"There are a few catches and caveats work mentioning, however"

Obviously, "work" should be "worth". There are instances like that
where a real editor should have caught it, but a Word Processor
wouldn't.

Mike

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


Re: Simple python iteration question

2007-08-15 Thread Roel Schroeven
Dennis Lee Bieber schreef:
> On Wed, 15 Aug 2007 13:39:57 -0300, "Gabriel Genellina"
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
> 
>> "Never underestimate the bandwidth of a station wagon full of tapes  
>> hurtling down the highway"
>> (Andrew S. Tanenbaum, Computer Networks, 1996; maybe the origin is much  
>> older)
> 
>   Considering how few "proper" "station wagons" were manufactured at
> that time period... Volvo was about it -- all the other makers tended to
> push "mini-vans"... Besides Volvo, I think the only current production
> station wagon is the Dodge Magnum (and that looks more like a
> chopped/channeled surfer hot-rod).

At least in Europe (including the Netherlands where Tanenbaum lives), 
station wagons were still popular then. Minivans have displaced them 
somewhat since then, but by 1996 there were still quite a few station 
wagons on the roads. There still are quite a few of them around; my boss 
just bought a new Saab 9-3 station wagon.

Manufacturers who made (and make) station wagons include VW (e.g. 
http://en.wikipedia.org/wiki/Image:Vw_passat_b3_v_sst.jpg), Mercedes 
(e.g. http://www.mediaweb06.com/diffusion/annonces/033f1ccd.jpg), BMW 
(e.g. http://www.degrifcars.com/images/BMW/Series3/b_Series3_break.jpg), 
Renault (e.g. 
http://www.carfolio.com/images/dbimages/zgas/models/id/9924/megane_break_1.9_rxe_d.jpg),
 
Ford (e.g. http://en.wikipedia.org/wiki/Image:Ford-Focus-wagon.jpg), 
Toyota (e.g. 
http://www.outrefranc.com/modeles/toyota/img/corollabreak3.jpg) and many 
others.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


Re: Module imports during object instantiation

2007-08-15 Thread Ritesh Raj Sarraf
Neil Cerutti wrote:

>>
>> Doesn't __init__ get called automatically ?
> 
> It gets called automatically when you construct an instance of
> the class in which it's defined.

I am a little confused by your statements now.

In my earlier posts in the same thread, I gave some code example which was
something like this:

class Log:
def __init__():
if os.name == 'posix':
try:
import foobar
except ImportError, e:
print >> sys.stderr, e

(Sorry for the bad indentation)

Now, what do you mean here by "construct an instance of the class in which
it is defined" ?

__init__() _is_ defined in the Log class and I try to create an instance of
the class Log as:

log = Log()

Assuming it is run on a box which is POSIX compliant, the try/import should
fail and I should see an error message because there is no module named
foobar. But I don't see that. And this is what exactly I wanted to get
clarified in this whole thread. (But still haven't got a clear answer to a
Yes/No).

Or am I terribly missing something that you are trying to tell ?

Ritesh
-- 
If possible, Please CC me when replying. I'm not subscribed to the list.

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


Layer 2 socket connection

2007-08-15 Thread alisonken1
Hello all -

I'm looking at trying to write a python script to connect to a layer 2
bridge (no IP available).

Looking at the sockets function, it's not clear if I can connect using
only the mac address - it appears to want either a broadcast address
or a specific IP address.

Can anyone give me a clue on opening a layer 2 socket in Python?

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


Re: Module imports during object instantiation

2007-08-15 Thread Neil Cerutti
On 2007-08-15, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote:
> Neil Cerutti wrote:
>
>>>
>>> Doesn't __init__ get called automatically ?
>> 
>> It gets called automatically when you construct an instance of
>> the class in which it's defined.
>
> I am a little confused by your statements now.
>
> In my earlier posts in the same thread, I gave some code example which was
> something like this:
>
> class Log:
> def __init__():
> if os.name == 'posix':
> try:
> import foobar
> except ImportError, e:
> print >> sys.stderr, e
>
> (Sorry for the bad indentation)
>
> Now, what do you mean here by "construct an instance of the class in which
> it is defined" ?
>
> __init__() _is_ defined in the Log class and I try to create an instance of
> the class Log as:
>
> log = Log()
>
> Assuming it is run on a box which is POSIX compliant, the
> try/import should fail and I should see an error message
> because there is no module named foobar. But I don't see that.
> And this is what exactly I wanted to get clarified in this
> whole thread. (But still haven't got a clear answer to a
> Yes/No).
>
> Or am I terribly missing something that you are trying to tell ?

I didn't see log = Log() in your example. Sorry for the
excursion.

Are you sure os.name is 'posix' on your system?

-- 
Neil Cerutti
We've got to pause and ask ourselves: How much clean air do we really need?
--Lee Iacocca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: All names in the current module

2007-08-15 Thread Lawrence Oluyede
Fabio Z Tessitore <[EMAIL PROTECTED]> wrote:
> to get names' list you can simply call globals()

Not strictly true. globals() returns the current's scope global vars. If
you import a module in the current scope globals() won't display the
names inside it.

-- 
Lawrence, oluyede.org - neropercaso.it
"It is difficult to get a man to understand 
something when his salary depends on not
understanding it" - Upton Sinclair
-- 
http://mail.python.org/mailman/listinfo/python-list


replacement for string.printable

2007-08-15 Thread John K Masters
>From what I have read the string module is obsolete and should not be
used but I am working on a project that parses printable files created
in a DOS program and creates a web page for each file. I am using the
string.printable constant to determine which characters should be kept;
the files contain many print control codes. There seems to be nothing
like this in the string methods. isalnum() seems the nearest but gives
false for '+' '!' etc.

I realise I could define a global string to cover this but wondered if
there was another, better, way

Regards, John
-- 
War is God's way of teaching Americans geography
Ambrose Bierce (1842 - 1914)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: encrypting files + filestreams?

2007-08-15 Thread Larry Bates
per9000 wrote:
> Hi python people,
> 
> I am trying to figure out the best way to encrypt files in python.
> 
> I've build a small script (see below) that encrypts the ubuntu 7.04
> iso file in 2 minutes (I like python :) ).
> 
> But I have some thoughts about it. By pure luck (?) this file happened
> to be N*512 bytes long so I do not have to add crap at the end - but
> on files of the size N*512 + M (M != 521) I will add some crap to make
> it fit in the algorithm. When I later decrypt I will have the stuff I
> do not want. How do people solve this? (By writing the number of
> relevant bytes in readable text in the beginning of the file?)
> 
> Also I wonder if this can be solved with filestreams (Are there
> streams in python? The only python file streams I found in the evil
> search engine was stuff in other forums.)
> 
> 
> Other comments are of course also welcome,
> Per
> 
> 
> # crypto_hardcoded.py starts here
> 
> from Crypto.Cipher import AES
> 
> def encrypt2(cryptor, infile, outfile):
> """enly encrypt a few bytes at a time"""
> 
> size = 512
> bytes = infile.read(size)
> 
> seek = 0
> interval = 97
> ctr = 0
> 
> while len(bytes) == size:
> seek += size
> if ctr % interval == 0:
> print '\r%15d bytes completed' %  (seek),
> ctr += 1
> 
> outfile.write(cryptor.encrypt(bytes))
> # change to this to decrypt
> # outfile.write(cryptor.decrypt(bytes))
> bytes = infile.read(size)
> 
> if len(bytes) != 0:
> bytes += "#" * (size - len(bytes))
> outfile.write(cryptor.encrypt(bytes))
> seek += len(bytes)
> 
> print '\r%15d bytes completed' %  (seek)
> 
> if __name__ == "__main__":
> crptz = AES.new("my-secret_passwd")
> ifile = file('/tmp/ubuntu-7.04-desktop-i386.iso','r')
> ofile = file('/tmp/ubuntu-7.04-desktop-i386.iso.out','w')
> 
> encrypt2(crptz, ifile, ofile)
> ifile.close()
> ofile.close()
> 
> # crypto_hardcoded.py ends here
> 

Padding and keeping information in a header is how I solved the problem.

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


Re: Move files/directories to Recycle Bin using standard Python libs

2007-08-15 Thread Chris Mellon
On 8/15/07, Kevin D.Smith <[EMAIL PROTECTED]> wrote:
> I would like to move files and directories to the Recycle Bin on
> Windows from Python.  I have found some older articles describing how
> to do this, but they require additional packages to be installed.  I'm
> working on a plugin for an existing project and only have the standard
> library to work with.  Is there a way to use the Recycle Bin using
> standard Python?
>
> --
> Kevin D. Smith


Not easily. The recycle bin is part of the shell, and the shell api
calls have very complicated struct parameters that are cumbersome to
use correctly from ctypes. If you do the work to map the fileop
structs to ctypes you can call the shell API file operation functions
in shell32.dll. This assumes that "standard" for you is Python 2.5,
which has ctypes. Otherwise you are out of luck.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: replacement for string.printable

2007-08-15 Thread Marc 'BlackJack' Rintsch
On Wed, 15 Aug 2007 19:56:01 +0100, John K Masters wrote:

> From what I have read the string module is obsolete and […]

The `string` module isn't obsolete.  It even contains a more or less
recent new addition: `Template`.  Only the functions that are also
available as methods on `str` are deprecated.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Layer 2 socket connection

2007-08-15 Thread Martin v. Löwis
> I'm looking at trying to write a python script to connect to a layer 2
> bridge (no IP available).
> 
> Looking at the sockets function, it's not clear if I can connect using
> only the mac address - it appears to want either a broadcast address
> or a specific IP address.
> 
> Can anyone give me a clue on opening a layer 2 socket in Python?

If your operating system supports the PF_PACKET protocol family, you
can try to use that. Python only wraps the socket interface of the
operating system, so if the system's socket implementation has no
facility for that, Python cannot expose it to you, either.

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


Re: All names in the current module

2007-08-15 Thread Ian Clark
Torsten Bronger wrote:
> Hallöchen!
> 
> How can I get a list with all classes defined in the current module?
> Thank you!
> 
> Tschö,
> Torsten.
> 

Assuming you want to see all classes in the re module:

 >>> import re
 >>> help(re) #best way
 >>>
 >>> def isclass(cls):
... try:
... return issubclass(cls, cls)
... except TypeError:
... pass
... return False
...
 >>> [cls for cls in dir(re) if isclass(getattr(re, cls))]
['Scanner', '_pattern_type', 'error']

Ian

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


Re: Simple python iteration question

2007-08-15 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
BartlebyScrivener  <[EMAIL PROTECTED]> wrote:
>On Aug 14, 11:59 am, "Shawn Milochik" <[EMAIL PROTECTED]> wrote:
>
>> Just for my own sanity: Isn't this the third response advocating the
>> use of enumerate()? Did the other responses not get through, or was
>> this a time-delay thing?
>>
>> Thanks,
>> Shawn
>
>Look at the timestamps.  All within ten minutes. And those ten minutes
>are spent keyboarding your response in and posting, plus it takes
>several minutes for the posts to appear on Google Groups.
>
>rd
>
>

... and now we've had two people reply with more-or-less the same
message to this question about the propriety of race conditions in
replies.  Go ahead, explain *that* level of abstracted confusion
to your civilian acquaintances in The Real World.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Layer 2 socket connection

2007-08-15 Thread alisonken1
On Aug 15, 12:05 pm, "Martin v. Löwis"

> If your operating system supports the PF_PACKET protocol family, you
> can try to use that. Python only wraps the socket interface of the
> operating system, so if the system's socket implementation has no
> facility for that, Python cannot expose it to you, either.
>
> Regards,
> Martin

I take it this means "Non-Unix variants" may have problems :)

Thanks, Martin. I'll have a look at that.

I'm working on a Linux platform, but there may be a need later on to
work with an MS platform as well (something for the boss).

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

Re: "Variable variable name" or "variable lvalue"

2007-08-15 Thread Marc 'BlackJack' Rintsch
On Wed, 15 Aug 2007 10:42:02 -0700, mfglinux wrote:

> I would like to know how to declare in python a "variable name" that
> it is in turn a variable
> In bash shell I would wrote sthg like:
> 
> for x in `seq 1 3`
> do
>   M$i=Material(x)  #Material is a python class
> done

You want a dictionary.

M = dict()
for x in xrange(1, 4):
M[x] = Material(x)

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Variable variable name" or "variable lvalue"

2007-08-15 Thread Larry Bates
mfglinux wrote:
> Hello to everybody
> 
> I would like to know how to declare in python a "variable name" that
> it is in turn a variable
> In bash shell I would wrote sthg like:
> 
> for x in `seq 1 3`
> do
>   M$i=Material(x)  #Material is a python class
> done
> 
> Why I need this? Cause I have a python module that obliges me to build
> a variable called Period, which should have a variable name of
> summands (depends on the value of x)
> 
> #Let's say x=3, then Period definition is
> Period=Slab(Material1(12.5)+Material2(25)+Material3(12.5)) #Slab is a
> python class
> 
> I dont know how to automatize last piece of code for any x
> 
> thank you
> 
> Marcos
> 
I think the answer is to use a dictionary of lists , but it is a little hard to
tell from your description:

mdict={1:[Material1, 12.5],
   2:[Material2, 25.0],
   3:[Material3, 12.5]
  }

x=3
slab_arg=0
for i in range(1,x):
func, farg=mdict[i]
slab_arg+=func(farg)

Period=Slab(slab_arg)

Obviously not tested!

I sense that the Material functions should be consolidated into something more
general here.

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


Re: Module imports during object instantiation

2007-08-15 Thread Ritesh Raj Sarraf
On Aug 15, 11:42 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote:
> On 2007-08-15, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote:
> > Or am I terribly missing something that you are trying to tell ?
>
> I didn't see log = Log() in your example. Sorry for the
> excursion.
>
> Are you sure os.name is 'posix' on your system?
>


Here again for you:

In [6]: cat rick.py
IPython system call: cat rick.py
import os, sys

class Log:
def __init__(self, verbose, lock = None):
self.VERBOSE = bool(verbose)
self.lock = bool(lock)

if self.lock:
self.dispLock = threading.Lock()
else:
self.dispLock = None

if os.name == 'posix':
try:
import foobar
except ImportError, e:
print >> sys.stderr, e

self.platform = 'posix'
self.color = get_colors()

elif os.name in ['nt', 'dos']:
self.platform = 'microsoft'
try:
import SomeModule
except ImportError, e:
# comment out next line before going to prod...
print >> sys.stderr, e

self.color = None
else:
self.color = SomeModule.get_colors_windows()
else:
self.platform = None
self.color = None

In [7]: from rick import Log

In [8]: log = Log(verbose = True)
No module named foobar
---
exceptions.NameError Traceback (most
recent call last)

/tmp/

/tmp/rick.py in __init__(self, verbose, lock)
 18
 19 self.platform = 'posix'
---> 20 self.color = get_colors()
 21
 22 elif os.name in ['nt', 'dos']:

NameError: global name 'get_colors' is not defined

In [9]: os.name
Out[9]: 'posix'

In [10]: import foobar
---
exceptions.ImportError   Traceback (most
recent call last)

/tmp/

ImportError: No module named foobar

In [11]:


Okay!! Ignore line 20 for now because that is not what this whole
thread has been about. In the code, just 2 lines above "self.color =
get_colors()" you see the try/except import statements. Since there is
no "foobar" named module, an ImportError should have been thrown and a
relevant error message should have been printed.
With these example I'm just trying to prove that imports put into a
class' __init__() never get executed. They get executed if you put
them in any of the methods. (And I don't know why it is done this
way).

Ritesh

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


  1   2   >