Re: ftp recursively

2008-03-20 Thread Paul Rubin
Jeff Schwab <[EMAIL PROTECTED]> writes:
> I thought os.walk was for locally mounted directories...  How is it
> relevant on remote filesystems?

Yes, os.walk is for local directories.  I thought you wanted to push a
local tree to a remote host.  For pulling, yes, you need to do
something different; for example, rsync can handle it for you.

> Don't shoot the messenger, but you're severely confused here.  Whether
> you're using ftp, rcp, or rsync is a completely separate issue to
> whether you're running over ssl (which I assume you meant by ssh).

SSL would make more sense but ssh is more commonly used.

> FTP is a work-horse protocol for transferring files.  It's going to be
> with us for a long, long time. 

Here's what happened when I just tried to use it:

$ ftp localhost
ftp: connect: Connection refused
ftp> 

That is quite common these days.  I think ftp doesn't play nicely with
encryption tunnels because of the way it uses a separate port for out
of band signalling, but I never paid close attention, so maybe there's
some other issue with it.  I can't think of when the last time was
that I actually used ftp.

> The point of rsync is to keep a local directory tree in sync with a
> remote one, by transferring only change-sets that are conceptually
> similar to patches.  If you're only transferring files once, there's
> no particular benefit (AFAIK) to using rsync rather than some kind of
> recursive ftp.

One benefit is that it handles the recursion for you by itself.
Another is that in modern unix environments it's more likely to work
at all (i.e. if there is no ftp server at the target machine).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding items that occur more than once in a list

2008-03-20 Thread John Machin
On Mar 20, 12:50 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Wed, 19 Mar 2008 20:16:36 -0300, John Machin <[EMAIL PROTECTED]>  
> escribió:
>
> > On Mar 20, 9:14 am, sturlamolden <[EMAIL PROTECTED]> wrote:
> >> Is a Python set implemented using a hash table?
>
> > What don't you understand about the comments in the first two
> > screenfuls of Objects/setobject.c?
>
> That comment was unnecesarily harsh, don't you think?
>
No, otherwise I wouldn't have made it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Removal of tkinter from python 3.0? [was: Fate of the repr module in Py3.0]

2008-03-20 Thread Daniel Fetchinson
> Was looking at PEP 3108, http://www.python.org/dev/peps/pep-3108/ ,
> and saw that the repr module was slated for vaporization. I've only
> used the module a few times ever. I'm curious if the community wants
> it kept around or whether it is considered clutter.
>
> The PEP is going to be finalized soon, so if you have issues with it,
> they should be sent to the PEP author or brought up on the list,
> http://mail.python.org/mailman/listinfo/stdlib-sig .

Is it just me or others also think that it would be a major loss to
remove tkinter from the python core? PEP 3108 starts off with:

Each module to be removed needs to have a justification as to why it
should no longer be distributed with Python.

then goes on with,

With so many other GUI options out there that are considered better
than Tkinter, it might be best to remove Tkinter from the stdlib and
make it an externally maintained package.

I don't get it. There are many [insert your favorite software
component] options outside of the python core that are considered
better than the one coming with python, yet they don't get removed.
All network servers for example could be thrown out because twisted is
considered better. This just doesn't make sense to me. Tkinter is
great for its purpose, typical use cases are creating a simple GUI
composed of a couple of components only. You can nicely do this with
tkinter and the large user base shows that it's a real need real
people have. Sure, for fancy GUI stuff there are better options but
for quick and simple things tkinter is just great. And last time I
checked python comes with batteries included so why sould I need to
search and download a third party package for such a common use case?

Thoughts anyone?

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


forkpty not working?

2008-03-20 Thread est
Hello everyone. I am trying to write a bash/ssh wrapper in python so
python scripts could interact with bash/ssh.

Because when input passwords to ssh it requires a tty rather than
stdin pipe, so i have to use a pty module to do that.

I copied this snippet from this thread
http://groups.google.com/group/comp.lang.python/browse_thread/thread/6bbc3d36b4e6ff55/

def rcmd(user, rhost, pw, cmd):
#Fork a child process, using a new pseudo-terminal as the
child's controlling terminal.
pid, fd = os.forkpty()
# If Child; execute external process
if pid == 0:
os.execv("/bin/ssh", ["/bin/ssh", "-l", user, rhost] +
cmd)
x=open("it_worked.txt", "w") #output a file for test
x.write("xxx")
x.close()
#if parent, read/write with child through file descriptor
else:
pause()
#Get password prompt; ignore
os.read(fd, 1000)
pause()
#write password
os.write(fd, pw + "\n")
pause()
res = ''
#read response from child process
s = os.read(fd,1 )
while s:
res += s
s = os.read(fd, 1)
return res

As far as I can see the code is not working, when called the function
rcmd() there is no file it_worked.txt spawned in the directory. I am
n00b to POSIX, so anyone please give me some hint? what happened when
os.forkpty()?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dividing tuple elements with an int or float

2008-03-20 Thread Steven D'Aprano
On Wed, 19 Mar 2008 23:06:44 -0700, royG wrote:


> suppose
> origsz=(400,300)
> i want to divide the origsize by 2.5 so i can resize to (160,120)
> 
> scale=2.5
> how can i get the newsz?
> obviously origsz/2.5 won't work  ..

newsz = (origsz[0]/scale, origsz[1]/scale)




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


Re: parsing json output

2008-03-20 Thread Gowri
Hi Tim,

I understand it's JSON. My problem is that it just prints crazy
characters instead of the JSON data. Like I mentioned, this happens on
my windows machine which has python 2.5. On the other hand, the same
code worked perfectly great on my linux machine with python 2.3.4.
What could the problem be?

Regards,
Gowri

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


Re: ftp recursively

2008-03-20 Thread Steven D'Aprano
On Wed, 19 Mar 2008 23:53:22 -0700, Jeff Schwab wrote:

> The point of rsync is to keep a local directory tree in sync with a
> remote one, by transferring only change-sets that are conceptually
> similar to patches.  If you're only transferring files once, there's no
> particular benefit (AFAIK) to using rsync rather than some kind of
> recursive ftp.

Avoiding re-inventing the wheel is a big benefit.


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


Re: Removal of tkinter from python 3.0? [was: Fate of the repr module in Py3.0]

2008-03-20 Thread Paul Rubin
"Daniel Fetchinson" <[EMAIL PROTECTED]> writes:
> Is it just me or others also think that it would be a major loss to
> remove tkinter from the python core?

That would be terrible.  Every time I've tried to use one of the other
packages it has led to installation hell.  Tkinter isn't great, but
it's extremely useful to have a gui module that's present
automatically in every compete Python installation and that is
reasonably cross platform.  I can write a Python/Tkinter app under
Linux and send it to Windows users and they can run it after a single,
very simple Python installation from the Windows .msi.  I have no
Windows development tools whatsoever and very limited access to
Windows boxes, so any Python code I deploy on Windows can't rely on
any non-Python code outside of the stdlib.

Also, because of tkinter's inherent limitations, I have the impression
that upgrading it to the latest and greatest tcl/tk release wouldn't
improve it much over the useful but low-rent module that it already is.
Therefore, that supposed "benefit" of splitting it out to an external
package is not much of a benefit.  

One of Python's traditionally best attractions has been the depth of
its standard libraries, and backing away from that would be plain
self-destructive.  Python needs more stuff in its stdlib, not less.
If Tkinter doesn't satisfy, then add Gtk (or whatever) to the standard
distro.  If that happens (i.e. some new toolkit is brought in and
declared to be the standard) then it might be ok to drop Tkinter but
it certainly shouldn't be dropped without a replacement.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this valid ?

2008-03-20 Thread Lie
On Mar 20, 4:18 am, Stef Mientki <[EMAIL PROTECTED]> wrote:
> hello,
>
> by accident I typed a double value test,
> and to my surprise it seems to work.
> Is this valid ?
>
> a = 2
> b = 2
>
> a == b == 2
>
> thanks,
> Stef Mientki

a == b == 2
is equivalent to
a == b and b == 2
except that b is only evaluated once for the whole comparison
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling Mac programs from Python instead of from AppleScript

2008-03-20 Thread Python.Arno


On 19 mrt 2008, at 20:41, [EMAIL PROTECTED] wrote:
>
> When I'm running Script Editor, I can get Maya to draw a sphere by
> typing:
>
> tell application "Maya"
>   execute "sphere"
> end tell
>
> When I try this using Python, I get this error message:
>
> IDLE 1.2.2
 app('Maya').execute('sphere')
>
> Traceback (most recent call last):
>  File "", line 1, in 
>app('Maya').execute('sphere')
> NameError: name 'app' is not defined

>
> Maybe I need to load some libraries first.
>

I never used applescript more than to record some clicks but you might  
try

tell application "/Applications/Autodesk/maya2008/Maya"

(replace maya2008 with you app's foldername)
or even

tell application "/Applications/Autodeks/maya2008/Maya/Contents/MacOS/ 
Maya"


> Please help me to get started.
>
like any other VFX app, maya is also adding python libs
you can access MEL commands from a python library:
http://www.autodesk.com/us/maya/docs/Maya85/wwhelp/wwhimpl/common/html/wwhelp.htm?context=DeveloperResources&file=Introduction_to_Maya_Python_API.html


> Thanks
> Dewey V. Schorre
>
gr
Arno Beekman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding items that occur more than once in a list

2008-03-20 Thread Arnaud Delobelle
On Mar 19, 3:08 am, Bryan Olson <[EMAIL PROTECTED]> wrote:
> Arnaud Delobelle wrote:
> > Ninereeds wrote:
> >> Hrvoje Niksic wrote:
> >>> This doesn't apply to Python, which implements dict storage as an
> >>> open-addressed table and automatically (and exponentially) grows the
> >>> table when the number of entries approaches 2/3 of the table size.
> >>> Assuming a good hash function, filling the dict should yield amortized
> >>> constant time for individual additions.
>
> > Isn't this average constant time rather than amortized?
>
> This is expected amortized constant time. Is that really the same
> thing as average constant time? Hmmm... that's subtle.

I am not sure what the difference between expected amortized time
complexity and average time complexity is (I know that they are
defined as different notions but I don't know whether they reduce to
the same thing or not).  Anyway both are average case complexities and
AFAIK worst case time complexity of insertion / lookup in a hashtable
is still O(n).

> >> OK. I obviously need to look up open-addressed tables. I thought this
> >> was just, in effect, implicit linked listing - ie it still needs a
> >> linear search to handle collisions, it just avoids the need for
> >> explicitly stored link fields. Perhaps I'm mistaken.
>
> The amortized doubling breaks that.
>
> > I don't think you are mistaken, but if I'm wrong I'd be grateful for a
> > link to further details.
>
> Arnaud Delobelle offered a good Wikipedia link, and for more background
> look up "amortized analysis.

Hrvoje Niksic provided the link :).  I still think two unrelated
things are being compared in this thread when people say that method A
(using dictionaries / sets) is O(n) and method B (sorting the list)
O(nlogn).

Isn't it the case that:

 | Worst case | Average case
-||-
Method A | O(n^2) | O(n)
Method B | O(nlogn)   | O(nlogn)

Which method is the best would then be determined by the distribution
of the hash values of your data, and whether you want to have a
guarantee the method will have a less-than-quadratic behaviour.

--
Arnaud

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


Re: Script Request...

2008-03-20 Thread Diez B. Roggisch
some one wrote:

> Thanks Diez, I found some docs and examples on urllib2.  Now how do i
> search the string I get from urllib2, lets say I put it in "myURL", How
> do I search for only Numbers and ".'s" in the "#.#.#.#" pattern.  That
> is all I am interested in with all the data retrieved.  Just the IP
> Address from amongst a bunch of data that I have no use of currently.
> 
> I would I write a pattern matching function to extract only the IP
> address from "myURL"?

Pattern-matching can be done using regular expressions, they are available
in the module "re".

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


backslash in reading bytes

2008-03-20 Thread Dravidan
I am trying to read some byte data as a string then using a library to
convert them a code:

>>>reader = csv.DictReader(open('table.txt'))
>>>def eleFind(value):
>>> for row in reader:
>>> if row['byteCode'] == value:
>>> print row['Element']
>>> return
>>> else:
>>> print "No Match Found:"
>>>eleFind('\x00\x00')

My table contains:

\x00\x00,
\x01\x00,
..

The program errors out.  How can I fix/overide this backslash issue.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: csv dictreader

2008-03-20 Thread Dravidan
It looks like the backslash is messing the whole thing up so I
reposted to try to find out how to get over the backslash hump.


On Mar 20, 2:08 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Wed, 19 Mar 2008 11:06:40 -0700 (PDT), brnstrmrs
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
>
> > my csv files looks like this:
>
> > Bytecode,Element
> > \x00\x00,
> > \x01\x00,0001
> > 
> > \x09\x00,0009
>
> I sure hope your data is more complex than that... otherwise it's a
> waste of space...
>
>  >>> for i in range(10):
> ... print i, repr(struct.pack("h", i))
> ...
> 0 '\x00\x00'
> 1 '\x01\x00'
> 2 '\x02\x00'
> 3 '\x03\x00'
> 4 '\x04\x00'
> 5 '\x05\x00'
> 6 '\x06\x00'
> 7 '\x07\x00'
> 8 '\x08\x00'
> 9 '\t\x00'
>
> And, \t is the same value \x09 (a tab character)
> --
> WulfraedDennis Lee Bieber   KD6MOG
> [EMAIL PROTECTED][EMAIL PROTECTED]
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff:   [EMAIL PROTECTED])
> HTTP://www.bestiaria.com/

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


Regarding Threads and locals()

2008-03-20 Thread Teja
Hi all,

I have a GUI applicaion(along with threads). When the run button is
pressed in the GUI a separate thread starts( Thread is created using
beginthreadex) and does the
required activity.
Now, while the thread is being executed, i want the locals() present
inside the thread's run function to be avaialbe in the GUI class from
where the thread class is being created

EG:
 --
main.py
--
class WorkerThread(threading.Thread):

def __init__(self, ):
 threading.Thread.__init__(self)
 # Start the thread and invoke the run method
 self.start()

def run(self):
  # Start the thread. It executed self.func() as a separate
thread
  self.workerThread, tid = win32process.beginthreadex(None,
0 , self.func ,(), 1)
  ...

 def func(self):
   execfile(temp.py)

class GUI(wxFrame):
   def __init__(self):
   .
   .
   def  CreateThread(self):

 self.workerThread = WorkerThread()


if name == _main_:
.
.
..
-
temp.py
--
  i = 1
  j = 2
  k = 4
  while(1):
print i
print j
print k
i = 1+1
j = j+2
k = k + 3


Now, while the thread is executin func and printing i, j, k , In the
main GUI thread how do i get the values of i, j ,k
I tried with sys.modules, sys._current_frames, vars(). But nothing
worked out.

Ideally the locals() of func() should be passed to the GUI thread,
how?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Script Request...

2008-03-20 Thread Gerard Flanagan
On Mar 19, 10:29 pm, some one <[EMAIL PROTECTED]> wrote:
> Thanks Diez, I found some docs and examples on urllib2.  Now how do i
> search the string I get from urllib2, lets say I put it in "myURL", How
> do I search for only Numbers and ".'s" in the "#.#.#.#" pattern.  That
> is all I am interested in with all the data retrieved.  Just the IP
> Address from amongst a bunch of data that I have no use of currently.
>
> I would I write a pattern matching function to extract only the IP
> address from "myURL"?
>

See the subsection titled 'Matching An IP Address', here:

http://www.oreilly.com/catalog/regex/chapter/ch04.html

Gerard

>
> > Show us your concrete efforts, and we will suggest improvements.
>
> > Diez

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


Re: Speaking Text

2008-03-20 Thread David C. Ullrich
On Wed, 19 Mar 2008 07:41:29 -0500, David C. Ullrich
<[EMAIL PROTECTED]> wrote:

>Mac OS X has text-to-speech built into the interface.
>So there must be a way to access that from the command
>line as well - in fact the first thing I tried worked:
>
>os.system('say hello')
>
>says 'hello'.
>
>Is there something similar in Windows and/or Linux?
>(If it's there in Linux presumably it only works if there
>happens to be a speech engine available...)

Thanks for the replies.

>David C. Ullrich

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


A question about a metacharacter

2008-03-20 Thread igbt
I am creating a simple script which is using gtk. In this script you
must enter a text, if you do not enter anything or you enter a dot,
the script will be finished. However, if you don't enter anything the
script works but if you enter a dot (.) the script does not work. I
was investigating about it and I think the problem is with the dot
character  sss == "." .  I was trying the same line with other
metacharacters like *, (, ) ...  and I found the same problem. I was
looking for an example where I could see the way I could do it without
any error but I did not find it. Could somebody tell me how can I
solve this error?



sss = entryName.get_text()  # The script gets the text
if sss == "" or sss == ".":
gtk.main_quit()#The script finishes


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


Strange behavior of the Eclipse embedded console

2008-03-20 Thread hellt
i've faced with some strangeness while executing this sample:

choice = raw_input("your choice: ")
print len(choice)

when i run this sample in my eclipse console with CPython and print
Yes, i have this output
4 #trailing \t is the fourth element

but when i use command line method
python sample.py
i have the correct length = 3

i'm curious now, can anyone explain that?

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


Re: Prototype OO

2008-03-20 Thread Bruno Desthuilliers
sam a écrit :
> 
> Some time ago (2004) there were talks about prototype-based languages 
> and Prothon emerged.
> 
> Can someone tell me why class-based OO is better that Prototype based, 

For which definition of "better" ?-)

> especially in scripting langage with dynamic types as Python is?
> 
> 
> Here are some links:
> 
> http://c2.com/cgi/wiki?PrototypeBasedProgramming

Most of the arguments in favor of prototypes seems to come to, mainly:
1/ it lets you customize behaviour on a per-object base
2/ it removes the mental overhead of inheritance, classes etc

Point 1. is a non-problem in Python, since you can already add/replace 
methods on a per-objec basis (ok, with a couple restrictions wrt/ 
__magic__ methods and such).

Point 2. is not (IMHO) such a problem in Python, where inheritance is 
mainly an implementation detail (it's not needed for polymorphic 
dispatch to work) and class hierarchy tend to be very flat, when they 
even exist.

Mainly, Python's object system is actually quite close to javascript 
here. That is, you get more or less the same flexibility. And a couple 
of powerful features you don't have with javascript (like hooks in the 
attribute lookup mechanism), too.





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


Re: A question about a metacharacter

2008-03-20 Thread Chris
On Mar 20, 1:19 pm, igbt <[EMAIL PROTECTED]> wrote:
> I am creating a simple script which is using gtk. In this script you
> must enter a text, if you do not enter anything or you enter a dot,
> the script will be finished. However, if you don't enter anything the
> script works but if you enter a dot (.) the script does not work. I
> was investigating about it and I think the problem is with the dot
> character  sss == "." .  I was trying the same line with other
> metacharacters like *, (, ) ...  and I found the same problem. I was
> looking for an example where I could see the way I could do it without
> any error but I did not find it. Could somebody tell me how can I
> solve this error?
>
> sss = entryName.get_text()      # The script gets the text
>         if sss == "" or sss == ".":
>                 gtk.main_quit()        #The script finishes
>
> Thanks ; -)

try this.

sss = entryName.get_text()
if not sss.strip() or sss.strip() == '.':
gtk.main_quit()

I wouldn't be suprised if your input is being captured with End-Of-
Line characters which would cause the mis-match.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Anomaly in time.clock()

2008-03-20 Thread Godzilla
Thanks Ross and John for your help. I apologise for the code I posted
earlier not being the full picture of what I was trying to achieve. I
had instantiated multiple instances of elapseTime class and each of
them gets called approximately the same time. Below is the updated
code:


import time
import thread
import Queue

printq = Queue.Queue(0)

class elapseTime:
def __init__(self, name=''):
  self.name = name
  self.timeStamp = None
  self.checkTimeFlag = False
  thread.start_new_thread(self.elapsedTime, ())

def setTime(self, state):
  if state == 1:
self.checkTimeFlag = True
self.timeStamp = time.clock()
  else:
self.checkTimeFlag = False

def elapsedTime(self):
  prevTime = time.clock()
  while True:
curTime = time.clock()
timeDiff = (curTime - prevTime)
if timeDiff < 0.0:
  printq.put_nowait('time.clock() has gone backward!!! Time
Diff '+str(timeDiff))
if self.checkTimeFlag:
  if (curTime - self.timeStamp) > 1.0:
printq.put_nowait(self.name+", actual Elapsed
Time"+str(round(curTime-self.timeStamp, 3)))
self.checkTimeFlag = False
prevTime = curTime
time.sleep(0.05)

def printmgr():
while True:
print printq.get(True)

# Print thread
thread.start_new_thread(printmgr, ())

objList = []
for i in range(10):
  objList.append(elapseTime("obj"+str(i)))

while True:
  for i in range(len(objList)):
  objList[i].setTime(1)
  time.sleep(10)
  print


When I run the above code long enough in the PC I see the
'time.clock() has gone backward!!!' statement being printed once in a
while. I have been reading a thread about invoking time.clock() at
close proximity caused the 'time warp' problem.

John, the PC experiencing this problem is a single core Intel Celeron
1GHz, XP SP2. The PC at home is a AMD Dual Core XP SP2.
-- 
http://mail.python.org/mailman/listinfo/python-list


Change user on UNIX

2008-03-20 Thread Giampaolo Rodola'
Hi all.
Is there any way to su or login as a different user within a python
script? I mainly need to temporarily impersonate another user to
execute a command and then come back to the original user.
I tried to google a little bit about it but I still didn't find a
solution.


Thanks in advance.

--- Giampaolo
http://code.google.com/p/pyftpdlib
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Change user on UNIX

2008-03-20 Thread Bjoern Schliessmann
Giampaolo Rodola' wrote:

> Is there any way to su or login as a different user within a
> python script? I mainly need to temporarily impersonate another
> user to execute a command and then come back to the original user.
> I tried to google a little bit about it but I still didn't find a
> solution.

IMHO, the cleanest way from a security perspective would be using
sudo. root can even configure it in a way that you don't have to
type a password.

Regards,


Björn

-- 
BOFH excuse #223:

The lines are all busy (busied out, that is -- why let them in to
begin with?).

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


Re: Calling Mac programs from Python instead of from AppleScript

2008-03-20 Thread has
On 19 Mar, 20:10, Kevin Walzer <[EMAIL PROTECTED]> wrote:

> Take a look at appscript:
>
> http://appscript.sourceforge.net/


Also, once appscript is installed, don't forget to import it before
use:

from appscript import *
app('Maya').execute('sphere')


HTH

has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net

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


eval and unicode

2008-03-20 Thread Laszlo Nagy
How can I specify encoding for the built-in eval function? Here is the 
documentation:

http://docs.python.org/lib/built-in-funcs.html

It tells that the "expression" parameter is a string. But tells nothing 
about the encoding. Same is true for: execfile, eval and compile.

The basic problem:

- expressions need to be evaluated by a program
- expressions are managed through a web based interface. The browser 
supports UTF-8, the database also supports UTF-8. The user needs to be 
able to enter string expressions in different languages, and store them 
in the database
- expressions are for filtering emails, and the emails can contain any 
character in any encoding

I tried to use eval with/without unicode strings and it worked. Example:

 >>> eval( u'"徹底したコスト削減 ÁÍŰŐÜÖÚÓÉ трирова"' ) == eval( '"徹底し 
たコスト削減 ÁÍŰŐÜÖÚÓÉ трирова"' )
True

The above test was made on Unbuntu Linux and gnome-terminal. 
gnome-terminal does support unicode. What would happen under Windows?

I'm also confused how it is related to PEP 0263. I always get a warning 
when I try to enter '"徹底したコスト削減 ÁÍŰŐÜÖÚÓÉ трирова"' in a source 
file without "# -*- coding: " specified. Why is it not the same for 
eval? Why it is not raising an exception (or why the encoding does not 
need to be specified?)

Thanks,

Laszlo

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

Re: A question about a metacharacter

2008-03-20 Thread igbt
On 20 mar, 12:38, Chris <[EMAIL PROTECTED]> wrote:
> On Mar 20, 1:19 pm, igbt <[EMAIL PROTECTED]> wrote:
>
>
>
> > I am creating a simple script which is using gtk. In this script you
> > must enter a text, if you do not enter anything or you enter a dot,
> > the script will be finished. However, if you don't enter anything the
> > script works but if you enter a dot (.) the script does not work. I
> > was investigating about it and I think the problem is with the dot
> > character  sss == "." .  I was trying the same line with other
> > metacharacters like *, (, ) ...  and I found the same problem. I was
> > looking for an example where I could see the way I could do it without
> > any error but I did not find it. Could somebody tell me how can I
> > solve this error?
>
> > sss = entryName.get_text()  # The script gets the text
> > if sss == "" or sss == ".":
> > gtk.main_quit()#The script finishes
>
> > Thanks ; -)
>
> try this.
>
> sss = entryName.get_text()
> if not sss.strip() or sss.strip() == '.':
> gtk.main_quit()
>
> I wouldn't be suprised if your input is being captured with End-Of-
> Line characters which would cause the mis-match.

It does not work. Thanks for your help
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Removal of tkinter from python 3.0? [was: Fate of the repr module in Py3.0]

2008-03-20 Thread Kay Schluehr
> Is it just me or others also think that it would be a major loss to
> remove tkinter from the python core? PEP 3108 starts off with:
>
> Each module to be removed needs to have a justification as to why it
> should no longer be distributed with Python.

>From time to time someone makes a serious claim about ineptness of
using significant whitespace on Windows servers because "My customer
doesn't let me install a reasonable editor. So I'm forced me to use MS
Notepad!". These poor guys can still use IDLE once they have a running
Python installation.

I'm definitely with you and batteries included.

Note also that Tk which seemed to be comatose for a long time seems to
recover and doesn't look that bad anyome:

http://www.tcl.tk/software/tcltk/8.5.html
http://wiki.tcl.tk/13636


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


Re: Removal of tkinter from python 3.0? [was: Fate of the repr module in Py3.0]

2008-03-20 Thread bearophileHUGS
Paul Rubin:
> Python needs more stuff in its stdlib, not less.
> If Tkinter doesn't satisfy, then add Gtk (or whatever) to the standard
> distro.  If that happens (i.e. some new toolkit is brought in and
> declared to be the standard) then it might be ok to drop Tkinter but
> it certainly shouldn't be dropped without a replacement.

If Tkinter is removed from the std lib, then I think another simple
GUI toolkit has to be added to replace it. I have appreciated Wax in
the past, it works with Wx and is rather easy. It's a dead software
now, but it can be improved. It can be almost as easy as Tk, and it
shows that Wx can be used with a much better API. Something like
gazpacho (http://gazpacho.sicem.biz/ ) can be created for Wax too, and
it can be added to the std lib.

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Removal of tkinter from python 3.0? [was: Fate of the repr module in Py3.0]

2008-03-20 Thread sturlamolden
On 20 Mar, 08:39, "Daniel Fetchinson" <[EMAIL PROTECTED]>
wrote:

> Thoughts anyone?

I don't use tk myself, but scheduling tkinter for vaporization would
be a bad idea. A lot of programs depend on it, and it doesn't look
ugly anymore (the one that ship with Python still does).

Would inclusion of wxPython and PyGTK in the standard library be an
option? Or does LGPL prevent it?







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


wxFormBuilder

2008-03-20 Thread sturlamolden

I just discovered wxFormBuilder. After having tried several GUI
builders for wx (including DialogBlocks, wxGlade, XRCed, Boa
constructor), this is the first one I can actually use.

To use it wxFormBuilder with wxPython, I generated an xrc resource and
loaded it with wxPython. All the tedious GUI coding is gone :-)

http://wxformbuilder.org/
http://wiki.wxpython.org/index.cgi/XRCTutorial


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


Re: os.path.getsize() on Windows

2008-03-20 Thread Duncan Booth
Steven D'Aprano <[EMAIL PROTECTED]> wrote:

> On Wed, 19 Mar 2008 12:34:34 +, Duncan Booth wrote:
>> By default Python on Windows allows you to open a file for reading
>> unless you specify a sharing mode which prevents it: 
> 
> But the OP is talking about another process having opened the file for 
> WRITING, not reading. It's that other process that has exclusive access, 
> and the OP was trying to determine when it was safe to attempt opening 
> the file according to whether or not it was still growing.
> 
No, unless the other process has specified that it wants exclusive access 
there is nothing stopping his process also opening the file. That's why he 
has to specify when he opens it that he wants exclusive access: then it 
doesn't matter what the other process does, he won't be able to open it 
until the other process has closed the file.

This all of course assumes that the other process writes the file in one 
single atomic chunk. If it were to create it and then separately open and 
write to it then all bets are off.
-- 
http://mail.python.org/mailman/listinfo/python-list


Thanks. (Re: keeping state in an iterator object by rebinding next())

2008-03-20 Thread Wilbert Berendsen
Thanks for all the elaborate answers and help! It helped me deepening my 
understanding of Python.
Sincere,
Wilbert Berendsen

-- 
http://www.wilbertberendsen.nl/
"You must be the change you wish to see in the world."
-- Mahatma Gandhi
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with PARAGRAPH SEPARATOR

2008-03-20 Thread Dominique . Holzwarth

Hello everyone

I'm doing a transformation with (MSXML) from a xml file to a tex file
(actually it's just output format "text" with tex commands inside).

The output of the transformation (a big string containg the whole file)
contains a so called 'paragraph separator' (unicode: 2029). If I want to
pring that string (file) to the std out or a file object then I get a
"UnicodeError" saying that the unicode 2029 can't be encoded...

Can anyone please tell me how I should handle that paragraph seperator?
I must say, that I don't even know WHY my output file has such a
character but I'd kinda like to keep it there and just be able to store
the string in a file object / print it to console...

Thanks in advance

Dominique

*
This e-mail and any files attached are strictly confidential, may be legally 
privileged and are intended solely for the addressee. If you are not the 
intended recipient please notify the sender immediately by return email and 
then delete the e-mail and any attachments immediately. The views and or 
opinions expressed in this e-mail are not necessarily the views of De La Rue 
plc or any of its subsidiaries and the De La Rue Group of companies, their 
directors, officers and employees make no representation about and accept no 
liability for its accuracy or completeness. You should ensure that you have 
adequate virus protection as the De La Rue Group of companies do not accept 
liability for any viruses 
De La Rue plc Registered No.3834125, De La Rue Holdings plc Registered No 58025 
and De La Rue International Limited Registered No 720284 are all registered in 
England with their registered office at: De La Rue House, Jays Close, Viables, 
Hampshire RG22 4BS
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this valid ?

2008-03-20 Thread Rolf van de Krol
John Machin wrote:
> Of course. You can chain comparisons as much as you like and is
> (semi-)sensible, e.g.
>   
Hmm, 'of course' is not the correct word for it. Although the Stef 
Mientki would probably be able to find it in the documentation it is not 
as simple as you might think.
Most languages interpret a == b == 2 as (a == b) == 2, or throw an error 
because this syntax is not valid. The fact that python understand the 
obvious meaning of this code, is quite unique to Python, as far as I know.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strange behavior of the Eclipse embedded console

2008-03-20 Thread hellt
On 20 мар, 14:31, hellt <[EMAIL PROTECTED]> wrote:
> i've faced with some strangeness while executing this sample:
>
> choice = raw_input("your choice: ")
> print len(choice)
>
> when i run this sample in my eclipse console with CPython and print
> Yes, i have this output
> 4 #trailing \t is the fourth element
>
> but when i use command line method
> python sample.py
> i have the correct length = 3
>
> i'm curious now, can anyone explain that?


just took a look into PyDEV-FAQ.

"The eclipse console is not an exact copy of a shell... one of the
changes is that when you press  in a shell, it may give you a
\r, \n or \r\n as an end-line char, depending on your platform. Python
does not expect this -- from the docs it says that it will remove the
last \n (checked in version 2.4), but, in some platforms that will
leave a \r there. This means that the raw_input() should usually be
used as raw_input().replace('\r', ''), and input() should be changed
for: eval(raw_input().replace('\r', ''))."



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

Deleting Microsoft access database

2008-03-20 Thread Ahmed, Shakir
I have a Microsoft Access database that I want to delete whether anyone
is using that file. 

The database is already read only mode residing in a server, users are
opening in read only mode. I want to delete that file, I remove read
only check but could not delete that file. 

Getting error message: 
Cannot delete xxx : It is being used by another person or program. 

Any help is highly appreciated.

Thanks
sa


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


Re: Deleting Microsoft access database

2008-03-20 Thread Michael Wieher
Are you going to be replacing it with a new database?

Problem: Users are accessing the file.  (as you said, users are opening in
read-only)
Solution: (assuming you will be using a new, better... anything is better
than M$, database) --- put the new database online, redirect your users to
hit the new database, once all connections are closed, delete the Access
database.
Alternate Solution: (if you aren't replacing it) Just turn the database
server off (that will kill any connections) and delete the database, or at
least disable that database from within the server itself (thus closing all
connections) and delete it.

Read only or not, the DB is still open, and can't be deleted while people
are connected.

2008/3/20, Ahmed, Shakir <[EMAIL PROTECTED]>:
>
> I have a Microsoft Access database that I want to delete whether anyone
> is using that file.
>
> The database is already read only mode residing in a server, users are
> opening in read only mode. I want to delete that file, I remove read
> only check but could not delete that file.
>
> Getting error message:
> Cannot delete xxx : It is being used by another person or program.
>
> Any help is highly appreciated.
>
> Thanks
> sa
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Deleting Microsoft access database

2008-03-20 Thread sturlamolden
On 20 Mar, 15:11, "Ahmed, Shakir" <[EMAIL PROTECTED]> wrote:
> I have a Microsoft Access database that I want to delete whether anyone
> is using that file.
>
> The database is already read only mode residing in a server, users are
> opening in read only mode. I want to delete that file, I remove read
> only check but could not delete that file.
>
> Getting error message:
> Cannot delete xxx : It is being used by another person or program.
>
> Any help is highly appreciated.

You cannot delete a file someone has open, in read-only mode or not.
Disconnect the computer from the network. If that does not help,
reboot the computer.




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


Re: Problem with PARAGRAPH SEPARATOR

2008-03-20 Thread Marc 'BlackJack' Rintsch
On Thu, 20 Mar 2008 13:03:17 +, Dominique.Holzwarth wrote:

> The output of the transformation (a big string containg the whole file)
> contains a so called 'paragraph separator' (unicode: 2029). If I want to
> pring that string (file) to the std out or a file object then I get a
> "UnicodeError" saying that the unicode 2029 can't be encoded...
> 
> Can anyone please tell me how I should handle that paragraph seperator?

You have to encode the unicode object in an encoding that know this
character.  UTF-8 might be a candidate encoding for this.

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


Re: dividing tuple elements with an int or float

2008-03-20 Thread Jerry Hill
On Thu, Mar 20, 2008 at 3:42 AM, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> On Wed, 19 Mar 2008 23:06:44 -0700, royG wrote:
>
>
>  > suppose
>  > origsz=(400,300)
>  > i want to divide the origsize by 2.5 so i can resize to (160,120)
>  >
>  > scale=2.5
>  > how can i get the newsz?
>  > obviously origsz/2.5 won't work  ..
>
>  newsz = (origsz[0]/scale, origsz[1]/scale)

That works fine for a 2-tuple, but might get unwieldy for larger
tuples, or if you don't know the length until runtime.  A more general
solution might use a generator expression, like this:

newsz = tuple(x/scale for x in origsz)

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


Re: eval and unicode

2008-03-20 Thread Jonathan Gardner
On Mar 20, 5:20 am, Laszlo Nagy <[EMAIL PROTECTED]> wrote:
> How can I specify encoding for the built-in eval function? Here is the
> documentation:
>
> http://docs.python.org/lib/built-in-funcs.html
>
> It tells that the "expression" parameter is a string. But tells nothing
> about the encoding. Same is true for: execfile, eval and compile.
>
> The basic problem:
>
> - expressions need to be evaluated by a program
> - expressions are managed through a web based interface. The browser
> supports UTF-8, the database also supports UTF-8. The user needs to be
> able to enter string expressions in different languages, and store them
> in the database
> - expressions are for filtering emails, and the emails can contain any
> character in any encoding
>
> I tried to use eval with/without unicode strings and it worked. Example:
>
>  >>> eval( u'"徹底したコスト削減 ÁÍŰŐÜÖÚÓÉ трирова"' ) == eval( '"徹底し
> たコスト削減 ÁÍŰŐÜÖÚÓÉ трирова"' )
> True
>
> The above test was made on Unbuntu Linux and gnome-terminal.
> gnome-terminal does support unicode. What would happen under Windows?
>
> I'm also confused how it is related to PEP 0263. I always get a warning
> when I try to enter '"徹底したコスト削減 ÁÍŰŐÜÖÚÓÉ трирова"' in a source
> file without "# -*- coding: " specified. Why is it not the same for
> eval? Why it is not raising an exception (or why the encoding does not
> need to be specified?)
>

Encoding information is only useful when you are converting between
bytes and unicode data. If you already have unicode data, you don't
need to do any more work to get unicode data.

Since a file can be in any encoding, it isn't apparent how to decode
the bytes seen in that file and turn them into unicode data. That's
why you need the # -*- coding magic to tell the python interpreter
that the bytes it will see in the file are encoded in a specific way.
Until we have a universal way to accurately find the encoding of every
file in an OS, we will need that magic. Who knows? Maybe one day there
will be a common file attribute system and one of the universal
attributes will be the encoding of the file. But for now, we are stuck
with ancient Unix and DOS conventions.

When you feed your unicode data into eval(), it doesn't have any
encoding or decoding work to do.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: backslash in reading bytes

2008-03-20 Thread Marc 'BlackJack' Rintsch
On Thu, 20 Mar 2008 03:24:49 -0700, Dravidan wrote:

> I am trying to read some byte data as a string then using a library to
> convert them a code:
> 
reader = csv.DictReader(open('table.txt'))
def eleFind(value):
for row in reader:
if row['byteCode'] == value:
print row['Element']
return
else:
print "No Match Found:"
eleFind('\x00\x00')
> 
> My table contains:
> 
> \x00\x00,
> \x01\x00,
> ..
> 
> The program errors out.  How can I fix/overide this backslash issue.

What does `errors out` mean?

It won't find two zero bytes.  What you give at the `eleFind()` call are
just *two* characters with a byte value of zero:

In [116]: len('\x00\x00')
Out[116]: 2

In [117]: print '\x00\x00'


In [118]: len('\\x00\\x00')
Out[118]: 8

In [119]: print '\\x00\\x00'
\x00\x00

The backslash has a special meaning in string literals.  If you don't want
this meaning, you have to escape it with another backslash.

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


Re: Change user on UNIX

2008-03-20 Thread Jonathan Gardner
On Mar 20, 4:51 am, "Giampaolo Rodola'" <[EMAIL PROTECTED]> wrote:
> Hi all.
> Is there any way to su or login as a different user within a python
> script? I mainly need to temporarily impersonate another user to
> execute a command and then come back to the original user.
> I tried to google a little bit about it but I still didn't find a
> solution.

In the unix world, this is highly discouraged. You shouldn't have to
change your user. The only user who can change roles---and who should
change roles for security reasons---is root.

The only reason sudo is around is for those people who really are root
but who don't like logging in as root to do root work. With a very
limited permission set for sudo, it is very, very easy to get full
root access.

  $ sudo cp /bin/cp /bin/cp.old; sudo cp /bin/su /bin/cp; sudo cp -
  #

If you want a different user to access files that another user
created, that's what groups are for. You should create a common group
and then share the files by assigning them to that group and setting
the appropriate permissions. Yes, this is painful, and every once in a
while you get files that don't have the right permissions or the group
is set to the wrong group. But this is the cost of running on a system
where multiple users can be doing things all at once, and the cost of
trying to make sure that users can't hurt each other. Someone
somewhere has to say, "You are allowed to do this much, but no more".

If that's not what you need, then you need to run the process as root.
It can change its user and even chroot to a jail if need be. This is
how apache, for instance, works. It starts as root and spawns the
server processes as the apache user.

(Apache does have an interesting problem with home directories, and it
has a very special solution that is very insecure. Even there, the
better solution is to put all the user's files under a common group in
a common folder outside of their home directories.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Can I dyanmically add Pyro objects to a running Pyro server?

2008-03-20 Thread writeson
Hi everyone,

I'm trying to build a distributed system using the code in the
examples/distributed_computing2 directory of the Pyro un-tarred
distribution. I'm trying to make this generic so one Pyro class can
kick off another on mulit-core/multi-cpu/multi-server systems. What
I'd like to know is this, after you've got the server.requestloop()
running in the Pyro server, is it possible to add objects to the
system? As in calling server.connect again with a new class and have
the daemon provide access to that. I'm essentially trying to
dynamically add Pyro objects to a running Pyro server.

Thanks in advance for your help,

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


Can I run a python program from within emacs?

2008-03-20 Thread jmDesktop
Hi, I'm trying to learn Python.  I using Aquamac an emac
implementation with mac os x.  I have a program.  If I go to the
command prompt and type pythong myprog.py, it works.  Can the program
be run from within the editor or is that not how development is done?
I ask because I was using Visual Studio with C# and, if you're
familiar, you just hit run and it works.  On Python do I use the
editor for editing only and then run the program from the command
line?  Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Change user on UNIX

2008-03-20 Thread Jeffrey Froman
Giampaolo Rodola' wrote:

> I mainly need to temporarily impersonate another user to
> execute a command and then come back to the original user.

If the script is run as root, you can freely impersonate other users with
the os.seteuid() and os.setegid() methods.

If the script is not run as root (either directly or through sudo, as
suggested by other posters), then perhaps it should be.


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


Re: Change user on UNIX

2008-03-20 Thread Jeff Schwab
Jonathan Gardner wrote:
> On Mar 20, 4:51 am, "Giampaolo Rodola'" <[EMAIL PROTECTED]> wrote:

>> Is there any way to su or login as a different user within a python
>> script? I mainly need to temporarily impersonate another user to
>> execute a command and then come back to the original user.

> In the unix world, this is highly discouraged. You shouldn't have to
> change your user.

> If you want a different user to access files that another user
> created, that's what groups are for.

What's your take on setuid scripts (Python or otherwise)?  I more or 
less agree with your assessment of su, so I would be interested in your 
opinion of chmod ug+s some_custom_script.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can I run a python program from within emacs?

2008-03-20 Thread Grant Edwards
On 2008-03-20, jmDesktop <[EMAIL PROTECTED]> wrote:

> Hi, I'm trying to learn Python.  I using Aquamac an emac
> implementation with mac os x.  I have a program.  If I go to the
> command prompt and type pythong myprog.py, it works.  Can the program
> be run from within the editor or is that not how development is done?
> I ask because I was using Visual Studio with C# and, if you're
> familiar, you just hit run and it works.  On Python do I use the
> editor for editing only and then run the program from the command
> line?

http://www.google.com/search?q=emacs+python

-- 
Grant

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


Re: Can I run a python program from within emacs?

2008-03-20 Thread Jeff Schwab
Grant Edwards wrote:
> On 2008-03-20, jmDesktop <[EMAIL PROTECTED]> wrote:
> 
>> Hi, I'm trying to learn Python.  I using Aquamac an emac
>> implementation with mac os x.  I have a program.  If I go to the
>> command prompt and type pythong myprog.py, it works.  Can the program
>> be run from within the editor or is that not how development is done?
>> I ask because I was using Visual Studio with C# and, if you're
>> familiar, you just hit run and it works.  On Python do I use the
>> editor for editing only and then run the program from the command
>> line?
> 
> http://www.google.com/search?q=emacs+python

Or achieve a similar (more flexible (IMO), but less smoothly integrated) 
effect with Vim and GNU Screen.  Until recently, you had to patch Screen 
if you wanted vertical splits, but now it's in the main line.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can I run a python program from within emacs?

2008-03-20 Thread jmDesktop
On Mar 20, 11:21 am, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2008-03-20, jmDesktop <[EMAIL PROTECTED]> wrote:
>
> > Hi, I'm trying to learn Python.  I using Aquamac an emac
> > implementation with mac os x.  I have a program.  If I go to the
> > command prompt and type pythong myprog.py, it works.  Can the program
> > be run from within the editor or is that not how development is done?
> > I ask because I was using Visual Studio with C# and, if you're
> > familiar, you just hit run and it works.  On Python do I use the
> > editor for editing only and then run the program from the command
> > line?
>
> http://www.google.com/search?q=emacs+python
>
> --
> Grant

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


RE: Problem with PARAGRAPH SEPARATOR

2008-03-20 Thread Dominique . Holzwarth

Actually that's what I tried to do, for example:
outputString = myString.encode('iso-8859-1','ignore')

However, I always get such messages (the character, that's causing problems 
varies, but its always higher than 127 ofc...)

'ascii' codec can't decode byte 0xc3 in position 51: ordinal not in range(128) 

It doesn't matter what encoding I use (tried 'utf-8' 'utf-16' 'latin_1' and the 
iso one). The debugger is showing all the special characters (from french and 
german language) so I'm wondering why there's still the message about the 
'ascii' codec...

Would that mean that the string "myString" is an ascii-string or what?

-Original Message-
From: Marc 'BlackJack' Rintsch [mailto:[EMAIL PROTECTED] 
Sent: Donnerstag, 20. März 2008 15:24
To: python-list@python.org
Subject: Re: Problem with PARAGRAPH SEPARATOR

On Thu, 20 Mar 2008 13:03:17 +, Dominique.Holzwarth wrote:

> The output of the transformation (a big string containg the whole 
> file) contains a so called 'paragraph separator' (unicode: 2029). If I 
> want to pring that string (file) to the std out or a file object then 
> I get a "UnicodeError" saying that the unicode 2029 can't be encoded...
> 
> Can anyone please tell me how I should handle that paragraph seperator?

You have to encode the unicode object in an encoding that know this character.  
UTF-8 might be a candidate encoding for this.

Ciao,
Marc 'BlackJack' Rintsch


*
This e-mail and any files attached are strictly confidential, may be legally 
privileged and are intended solely for the addressee. If you are not the 
intended recipient please notify the sender immediately by return email and 
then delete the e-mail and any attachments immediately. The views and or 
opinions expressed in this e-mail are not necessarily the views of De La Rue 
plc or any of its subsidiaries and the De La Rue Group of companies, their 
directors, officers and employees make no representation about and accept no 
liability for its accuracy or completeness. You should ensure that you have 
adequate virus protection as the De La Rue Group of companies do not accept 
liability for any viruses 
De La Rue plc Registered No.3834125, De La Rue Holdings plc Registered No 58025 
and De La Rue International Limited Registered No 720284 are all registered in 
England with their registered office at: De La Rue House, Jays Close, Viables, 
Hampshire RG22 4BS
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can I run a python program from within emacs?

2008-03-20 Thread Michael Wieher
Well, I suppose you could.  But why bother with learing emacs when you'll
have to switch to vim later anyway?

2008/3/20, jmDesktop <[EMAIL PROTECTED]>:
>
> Hi, I'm trying to learn Python.  I using Aquamac an emac
> implementation with mac os x.  I have a program.  If I go to the
> command prompt and type pythong myprog.py, it works.  Can the program
> be run from within the editor or is that not how development is done?
> I ask because I was using Visual Studio with C# and, if you're
> familiar, you just hit run and it works.  On Python do I use the
> editor for editing only and then run the program from the command
> line?  Thank you.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Prototype OO

2008-03-20 Thread sam
Bruno Desthuilliers napisał(a):

> Most of the arguments in favor of prototypes seems to come to, mainly:
> 1/ it lets you customize behaviour on a per-object base
> 2/ it removes the mental overhead of inheritance, classes etc
> 
> Point 1. is a non-problem in Python, since you can already add/replace 
> methods on a per-objec basis (ok, with a couple restrictions wrt/ 
> __magic__ methods and such).
> 
> Point 2. is not (IMHO) such a problem in Python, where inheritance is 
> mainly an implementation detail (it's not needed for polymorphic 
> dispatch to work) and class hierarchy tend to be very flat, when they 
> even exist.
> 
> Mainly, Python's object system is actually quite close to javascript 
> here. That is, you get more or less the same flexibility. And a couple 
> of powerful features you don't have with javascript (like hooks in the 
> attribute lookup mechanism), too.

Thanks for precise opinion and spending your time.


I think that when you use statically typed language, than you have to define 
classes, because compiler has to know what is allowed to do with instances of 
that class.

But when you use dynamically typed language, then classes are redundant, 
because 
object is looked at when it is referenced. Dynamically typed language needs 
only 
objects hierarchy and you can add properties (methods, values) to that object 
during program execution.

In dynamically typed language when you create object A that is inherited from 
another object B, than object A knows that B is his predecessor. So when you 
reference A.prop, then prop is looked in A first, then in B, then in 
predecessors of B, and so on.

Having object A you can access its predecessor B. When you have access to 
object 
B, then you can add properties to it and these properties could be accessed by 
all other objects inherited from B.

You can do all these things in Python. But why it uses classes?

So you can say: "CLASS BASED PROGRAMMING" == "STATICALY TYPED LANGUAGE"





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


Re: Can I run a python program from within emacs?

2008-03-20 Thread Jeff Schwab
jmDesktop wrote:
> On Mar 20, 11:21 am, Grant Edwards <[EMAIL PROTECTED]> wrote:
>> On 2008-03-20, jmDesktop <[EMAIL PROTECTED]> wrote:
>>
>>> Hi, I'm trying to learn Python.  I using Aquamac an emac
>>> implementation with mac os x.  I have a program.  If I go to the
>>> command prompt and type pythong myprog.py, it works.  Can the program
>>> be run from within the editor or is that not how development is done?
>>> I ask because I was using Visual Studio with C# and, if you're
>>> familiar, you just hit run and it works.  On Python do I use the
>>> editor for editing only and then run the program from the command
>>> line?

Sort of.  Modern editors generally have support for building and running 
your program directly from a toolbar button or textual command.  I 
personally use Vim with the toolbar disabled, running in a Terminal, and 
run the program by first putting Vim in the background (^z).

People writing code specific to Mac, but not necessarily all in Python, 
often use XCode.

 http://zovirl.com/2006/07/13/xcode-python/

In the Ruby community, Vim is the dominant choice, but a lot of Mac 
users swear by TextMate.

 http://macromates.com/

>> http://www.google.com/search?q=emacs+python

> Gee.  Thanks.

I believe Grant was suggesting that Emacs often serves a similar purpose 
on Unix to what Visual Studio does on Windows, which seemed to be what 
you were asking.  When asking about Mac OS X here, you are likely to get 
a lot of generic Unix responses.  (Would it have been clearer if he had 
just said "emacs?")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxFormBuilder

2008-03-20 Thread DoxaLogos
On Mar 20, 8:41 am, sturlamolden <[EMAIL PROTECTED]> wrote:
> I just discovered wxFormBuilder. After having tried several GUI
> builders for wx (including DialogBlocks, wxGlade, XRCed, Boa
> constructor), this is the first one I can actually use.
>
> To use it wxFormBuilder with wxPython, I generated an xrc resource and
> loaded it with wxPython. All the tedious GUI coding is gone :-)
>
> http://wxformbuilder.org/http://wiki.wxpython.org/index.cgi/XRCTutorial

I've stumbled across it myself and have found it superior so far over
the others.  I just wish it could also crank out wxPython code.  I'm
still hoping one day for a form designer closer to Visual Studio's
form designer in ease of use area.  FarPy GUIE has the right idea, but
not near enough widget support.  And, I'm not good enough at wxPython
yet to be able help either project.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can I run a python program from within emacs?

2008-03-20 Thread Paulo da Costa
Jeff Schwab wrote:
> jmDesktop wrote:
>> On Mar 20, 11:21 am, Grant Edwards <[EMAIL PROTECTED]> wrote:
>>> On 2008-03-20, jmDesktop <[EMAIL PROTECTED]> wrote:
>>>
 Hi, I'm trying to learn Python.  I using Aquamac an emac
 implementation with mac os x.  I have a program.  If I go to the
 command prompt and type pythong myprog.py, it works.  Can the program
 be run from within the editor or is that not how development is done?
 I ask because I was using Visual Studio with C# and, if you're
 familiar, you just hit run and it works.  On Python do I use the
 editor for editing only and then run the program from the command
 line?
> 
> Sort of.  Modern editors generally have support for building and running 
> your program directly from a toolbar button or textual command.  I 
> personally use Vim with the toolbar disabled, running in a Terminal, and 
> run the program by first putting Vim in the background (^z).

Modern editors like GNU Emacs show you a Python tab when you're editing 
a Python file that allows you to do various things with the code, just 
like Visual Studio, I don't know about "Aquamacs".

> I believe Grant was suggesting that Emacs often serves a similar purpose 
> on Unix to what Visual Studio does on Windows, which seemed to be what 
> you were asking.  When asking about Mac OS X here, you are likely to get 
> a lot of generic Unix responses.  (Would it have been clearer if he had 
> just said "emacs?")

There are several flavors, it's best to specify which one you mean. 
People who say Emacs often mean GNU Emacs.

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


Re: Can I run a python program from within emacs?

2008-03-20 Thread jmDesktop
On Mar 20, 11:44 am, Jeff Schwab <[EMAIL PROTECTED]> wrote:
> jmDesktop wrote:
> > On Mar 20, 11:21 am, Grant Edwards <[EMAIL PROTECTED]> wrote:
> >> On 2008-03-20, jmDesktop <[EMAIL PROTECTED]> wrote:
>
> >>> Hi, I'm trying to learn Python.  I using Aquamac an emac
> >>> implementation with mac os x.  I have a program.  If I go to the
> >>> command prompt and type pythong myprog.py, it works.  Can the program
> >>> be run from within the editor or is that not how development is done?
> >>> I ask because I was using Visual Studio with C# and, if you're
> >>> familiar, you just hit run and it works.  On Python do I use the
> >>> editor for editing only and then run the program from the command
> >>> line?
>
> Sort of.  Modern editors generally have support for building and running
> your program directly from a toolbar button or textual command.  I
> personally use Vim with the toolbar disabled, running in a Terminal, and
> run the program by first putting Vim in the background (^z).
>
> People writing code specific to Mac, but not necessarily all in Python,
> often use XCode.
>
>      http://zovirl.com/2006/07/13/xcode-python/
>
> In the Ruby community, Vim is the dominant choice, but a lot of Mac
> users swear by TextMate.
>
>      http://macromates.com/
>
> >>http://www.google.com/search?q=emacs+python
> > Gee.  Thanks.
>
> I believe Grant was suggesting that Emacs often serves a similar purpose
> on Unix to what Visual Studio does on Windows, which seemed to be what
> you were asking.  When asking about Mac OS X here, you are likely to get
> a lot of generic Unix responses.  (Would it have been clearer if he had
> just said "emacs?")

No.  Typically when someone posts a one-liner search it means go
figure it out and stop bothering "us."  I had already searched.  I
could not get it to work, which is why I posted.  If I took it wrong I
apologize.

I really had two questions.  One is just how to run a program from
within the editor and the other is if my thinking on how development
is done in python wrong to start with.  Most of my non-Windows
programs have been on Unix using vi, but it has been a while.  I'm
used to writing a program in visual studio and running it.  If that's
the wrong expectation for python programming in emacs, then I wanted
to know.

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


Re: Can I run a python program from within emacs?

2008-03-20 Thread Grant Edwards
On 2008-03-20, jmDesktop <[EMAIL PROTECTED]> wrote:
> On Mar 20, 11:21 am, Grant Edwards <[EMAIL PROTECTED]> wrote:
>> On 2008-03-20, jmDesktop <[EMAIL PROTECTED]> wrote:
>>
>> > Hi, I'm trying to learn Python.  I using Aquamac an emac
>> > implementation with mac os x.  I have a program.  If I go to the
>> > command prompt and type pythong myprog.py, it works.  Can the program
>> > be run from within the editor or is that not how development is done?
>> > I ask because I was using Visual Studio with C# and, if you're
>> > familiar, you just hit run and it works.  On Python do I use the
>> > editor for editing only and then run the program from the command
>> > line?
>>
>> http://www.google.com/search?q=emacs+python
>
> Gee.  Thanks.

Golly.  You're welcome.  Don't the hits on the first page
answer your question?  They explain how to do things like run
python programs from within emacs (including how to do
source-level debugging).

This is probably one of the better pages that the google search
above found:

http://wiki.python.org/moin/EmacsEditor

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


Re: Can I run a python program from within emacs?

2008-03-20 Thread Grant Edwards
On 2008-03-20, Jeff Schwab <[EMAIL PROTECTED]> wrote:

>>> http://www.google.com/search?q=emacs+python
>
>> Gee.  Thanks.
>
> I believe Grant was suggesting that Emacs often serves a similar purpose 
> on Unix to what Visual Studio does on Windows, which seemed to be what 
> you were asking.  When asking about Mac OS X here, you are likely to get 
> a lot of generic Unix responses.  (Would it have been clearer if he had 
> just said "emacs?")

Don't the normal "run/debug python from inside emacs" methods
work on OS-X?

-- 
Grant

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


pep 3108

2008-03-20 Thread Daniel Fetchinson
Hi Brett,

I've just looked through pep 3108 and since Raymond Hettinger
suggested contacting you if we "have issues with it", here it goes:

I don't think it would be a great idea to move tkinter from the core
to a third party library because once that happens we can no longer
assume that any GUI library is present on a box with python installed.
Of course it's not a big deal to install an extra package but when it
comes to distribution customers/friends/family/etc are forced to
install the third party package too and that is beyond the control of
the developer (are they willing to do it? are they able to do it? do
they think it's a hassle?).

I've brought up the issue on c.l.p and people seem to agree, please
see the thread for additional detail:

http://tinyurl.com/2v4mh3

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


if __name__ == '__main__':

2008-03-20 Thread Bhagwat Kolde
Hi,
I am new to the python and not getting meaning of following line,

if __name__ == '__main__':
  main()

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

Re: Can I run a python program from within emacs?

2008-03-20 Thread Grant Edwards
On 2008-03-20, jmDesktop <[EMAIL PROTECTED]> wrote:

>> I believe Grant was suggesting that Emacs often serves a
>> similar purpose on Unix to what Visual Studio does on Windows,
>> which seemed to be what you were asking.  When asking about
>> Mac OS X here, you are likely to get a lot of generic Unix
>> responses.  (Would it have been clearer if he had just said
>> "emacs?")
>
> No.  Typically when someone posts a one-liner search it means
> go figure it out and stop bothering "us." I had already
> searched.  I could not get it to work,

Could not get what to work?

> which is why I posted.  If I took it wrong I apologize.

I honestly thought you were asking how to run/debug python
programs inside emacs.  A couple of the hits answered that
question.  The others explained how do get python-aware editing
modes configured.

> I really had two questions.  One is just how to run a program from
> within the editor and the other is if my thinking on how development
> is done in python wrong to start with.  Most of my non-Windows
> programs have been on Unix using vi, but it has been a while.  I'm
> used to writing a program in visual studio and running it.

Perhaps you'd be more comfortable with one of the IDEs?

http://wiki.python.org/moin/IntegratedDevelopmentEnvironments
http://en.wikipedia.org/wiki/Comparison_of_integrated_development_environments#Python

> If that's the wrong expectation for python programming in
> emacs, then I wanted to know.

Yes, you can run programs (including python debuggers) from
inside emacs.  The simplest way is to do "meta-x shell" to get
a shell prompt inside emacs, then just type whatever command
line you want to use to run the program.  Or you can map a
command to a keystroke that will run the program.

I generally just have another terminal window open where I run
the program -- but I've never liked IDEs so your tastes may
differ.

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


RE: paramiko

2008-03-20 Thread Tarun Kapoor
I have some code that uses paramiko, establishes an SFTP connection with
a remote server and downloads some files. This code works perfect if run
on a windows XP machine. However, I get an error in the "RandomPool"
class. 
Anyone tried paramiko on a windows server box ?
Thanks !!
Tk


-Original Message-
From: Guilherme Polo [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, January 16, 2008 11:12 AM
To: Tarun Kapoor; python-list@python.org
Subject: Re: paramiko

2008/1/16, Tarun Kapoor <[EMAIL PROTECTED]>:
>
>
>
>
> I am using paramiko to do an SFTP file transfer... I was able to
connect to
> the remote server using an SFTP client I have just to make sure that
> username and password are working.. This is the code.
>
>
>
> # now, connect and use paramiko Transport to negotiate SSH2 across
the
> connection
>
> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>
> sock.connect((hostname, port))
>
>
>
> t = paramiko.Transport(sock)
>
> event = threading.Event()
>
> t.start_client(event)
>
>
>
> event.wait(15)
>
>
>
> if not t.is_active():
>
> print 'SSH negotiation failed.'
>
> sys.exit(1)
>
> else:
>
> print "SSH negotiation sucessful"
>
>
>
> event.clear()
>
>
>
> t.auth_password(username=username, password=password,event=event)
>
>
>
> if not t.is_authenticated():
>
> print "not authenticated"
>
> output:
>
> SSH negotiation successful
>
> not authenticated
>
>
>
>
>
>
>
> Tarun
>
>
>
> Waterstone Capital Management
>
> 2 Carlson Parkway, Suite 260
>
> Plymouth, MN 55447
>
>
>
> Direct: 952-697-4123
>
> Cell:612-205-2587
>  Disclaimer This e-mail and any attachments is confidential and
intended
> solely for the use of the individual(s) to whom it is addressed. Any
views
> or opinions presented are solely those of the author and do not
necessarily
> represent those of Waterstone Capital Management, L.P and affiliates.
If you
> are not the intended recipient, be advised that you have received this
> e-mail in error and that any use, dissemination, printing, forwarding
or
> copying of this email is strictly prohibited. Please contact the
sender if
> you have received this e-mail in error. You should also be aware that
> e-mails are susceptible to interference and you should not assume that
the
> contents of this e-mail originated from the sender above or that they
have
> been accurately reproduced in their original form. Waterstone Capital
> Management, L.P. and affiliates accepts no responsibility for
information,
> or errors or omissions in this e-mail or use or misuse thereof. If in
doubt,
> please verify the authenticity with the sender.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

You are missing an event.wait() after t.auth_password.
Also, why are you passing this magic value "15" to event.wait() ? That
parameter is passed to class _Verbose to indicate if debug messages
should be displayed or not, so typical values would be 0/1 or
False/True.

-- 
-- Guilherme H. Polo Goncalves


Disclaimer

This e-mail and any attachments is confidential and intended solely for the use 
of the individual(s) to whom it is addressed. Any views or opinions presented 
are solely those of the author and do not necessarily represent those of 
Waterstone Capital Management, L.P and affiliates. If you are not the intended 
recipient, be advised that you have received this e-mail in error and that any 
use, dissemination, printing, forwarding or copying of this email is strictly 
prohibited. Please contact the sender if you have received this e-mail in 
error. You should also be aware that e-mails are susceptible to interference 
and you should not assume that the contents of this e-mail originated from the 
sender above or that they have been accurately reproduced in their original 
form. Waterstone Capital Management, L.P. and affiliates accepts no 
responsibility for information, or errors or omissions in this e-mail or use or 
misuse thereof. If in doubt, please verify the authenticity with the!
  sender.


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


Re: Pycon disappointment

2008-03-20 Thread atom . anderson
On Mar 17, 1:20 am, Paul Rubin  wrote:
> Stephan Deibel <[EMAIL PROTECTED]> writes:
> > I have to admit, I'll keep coming to PyCon even if all the talks suck
> > abysmally as long as there's good hallway time, open space, BoFs, and
> > sprints. ;-)
>
> OK, so why not get rid of all the talks and other stuff, and just have
> a basically structureless conference, beyond scheduling some open
> meetings on various topics?  That would be a lot less expensive and a
> lot more interesting.

For me as first time pycon attendee, i think this would be an absolute
disaster.  The talks gave me an opportunity to sit next to new people
and meet people I wouldnt have otherwise if they had simply "put us
out to pasture" to chat it up.

I think for devs that are just meeting each other, having some sort of
subject matter to talk about is a big deal, and the talks forced
that.  I agree though that once things get going, the hallway time and
BOF time would be fantastic.

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


Re: if __name__ == '__main__':

2008-03-20 Thread Simon Brunning
On Thu, Mar 20, 2008 at 4:12 PM, Bhagwat Kolde <[EMAIL PROTECTED]> wrote:
> Hi,
> I am new to the python and not getting meaning of following line,
>
> if __name__ == '__main__':
>   main()



-- 
Cheers,
Simon B.
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues
-- 
http://mail.python.org/mailman/listinfo/python-list


OS.remove and threads

2008-03-20 Thread rodmc
Hi,

I am writing a small application which uploads files in a thread via
an ftp connection. However anytime I use the os.remove(filename)
command to delete files the thread crashes, even if the file being
removed has nothing to do with the one being uploaded. Are the OS
commands incompatible with threads? By crashing I mean the thread
stops uploading and an exception is produced. Also if the OS commands
are in any other thread, they cause that thread to crash. I have tried
using locks around the os.remove command but that also makes no
difference.

I am using: Mac OS 10.4.9 and Python 2.4.3 with Psyco.

Kind regards,

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


Re: wxFormBuilder

2008-03-20 Thread Stef Mientki
sturlamolden wrote:
> I just discovered wxFormBuilder. After having tried several GUI
> builders for wx (including DialogBlocks, wxGlade, XRCed, Boa
> constructor), this is the first one I can actually use.
> 
> To use it wxFormBuilder with wxPython, I generated an xrc resource and
> loaded it with wxPython. All the tedious GUI coding is gone :-)
> 
> http://wxformbuilder.org/
> http://wiki.wxpython.org/index.cgi/XRCTutorial
> 
> 

I've tried several of the above mentioned builders,
with the same result.
I've also looked at wxFormBuilder,
but I found it far too difficult and
fully unreadable (how can you create actions/bindings on components you don't 
see ?).
So I might be very very naive,
but why all so complex ??

I wrote a few lines of code,
and now all my form designs look as simple as this:

 GUI = """
 self.Splitter_Plots,SplitterVer
   self.Panel   ,PanelVer, 010
 self.Panel_Top ,PanelHor, 11
   Label_Top,wx.StaticText
 self.Scope_Canvas  ,PlotCanvas ,self, Real_Time
 self.Panel_Bottom  ,PanelHor
   Label_Bottom ,wx.StaticText
   self.Scope_History   ,PlotCanvas_History ,self, Real_Time
 """
 exec ( Create_GUI ( GUI, 'Plots_Dock' ) )

cheers,
Stef
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can I run a python program from within emacs?

2008-03-20 Thread Diez B. Roggisch
Grant Edwards wrote:

> On 2008-03-20, Jeff Schwab <[EMAIL PROTECTED]> wrote:
> 
 http://www.google.com/search?q=emacs+python
>>
>>> Gee.  Thanks.
>>
>> I believe Grant was suggesting that Emacs often serves a similar purpose
>> on Unix to what Visual Studio does on Windows, which seemed to be what
>> you were asking.  When asking about Mac OS X here, you are likely to get
>> a lot of generic Unix responses.  (Would it have been clearer if he had
>> just said "emacs?")
> 
> Don't the normal "run/debug python from inside emacs" methods
> work on OS-X?

Of course they do.

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


Re: if __name__ == '__main__':

2008-03-20 Thread Michael Wieher
Well, consider this:

you have a file named .py, built like this:
~
#!/usr/bin/python

def :

return 

if __name__=="__main__":
print "Unit test"
else:
pass #module imported by another module/script
~~

If you type, on command line, >python ./.py
you will see "Unit test" printed to the screen.

if, however you are in another python file and type "import " the
code will, instead, "pass" and nothing will occur.

I hope this helps =)


2008/3/20, Simon Brunning <[EMAIL PROTECTED]>:
>
> On Thu, Mar 20, 2008 at 4:12 PM, Bhagwat Kolde <[EMAIL PROTECTED]> wrote:
> > Hi,
> > I am new to the python and not getting meaning of following line,
> >
> > if __name__ == '__main__':
> >   main()
>
> <
> http://www.python.org/doc/faq/programming/#how-do-i-find-the-current-module-name
> >
>
> --
> Cheers,
> Simon B.
> [EMAIL PROTECTED]
> http://www.brunningonline.net/simon/blog/
> GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Problem with PARAGRAPH SEPARATOR

2008-03-20 Thread Richard Brodie

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

> Would that mean that the string "myString" is an ascii-string or what?

It would mean it was a byte encoded string already, yes. When you try to
encode it, Python tries to coerce it to Unicode and it's equivalent to:

myString.decode('ascii').encode('iso-8859-1','ignore')

That wouldn't explain why printing it gave errors though. 


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


Import a file to namespace

2008-03-20 Thread Pedro Machado Santa
Hi all,

I'm really a newbie in Python, and I wanted to do a tricky thing. I
don't know if it is possible but my intention was: I have a package
(namely breve) and I want to alter (override?) some of it's functions
preserving the original library/package - in order if I update it, I
do not lose my "hacks".

Until now I was overriding the functions directcly on my script and
adding them to the package namespace, like this:

import testpackage

class testClass():
#...

testpackage.testClass =  testClass


But this has a problem. If I wanna use that code over many files, I
have to update it manually on all of them every time I update my
"hack". I was thinking if it is possible to keep that code on a file -
namely testpackageaddon.py and import it on my work file so that by
doing that it will automatically override the classes. Like so:

import testpackage
import testpackageaddon

testpackage.testClass() #my hacked class defined on
testpackageaddon.py


And on testpackageaddon.py:

import testpackage

class testClass():
#...

testpackage.testClass =  testClass


Any tips, ideas on how to do this?

Many thanks.

Pedro Machado Santa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pycon disappointment

2008-03-20 Thread atom . anderson
Okay!

I just read this entire thread to be caught up.  I am a first time
PyCon-goer (as my previous post states).  Because I have nothing to
compare this year's experience to, I'll give it to you as I saw it.
None of this is intended as a rant, (except maybe the lightning talk
section;)

Gripes
--

Numero Uno:  The Lightning Talks.

The best lightning talk I saw was the one where the guy's code didn't
work and he couldn't believe it or simply move on with his
presentation, it was hilarious but I felt bad for the guy.

I have to be honest, I had heard GREAT things about the lightning
talks and I went to the session expecting to hear something great, or
at least feel the same sense of community I felt when discussing
python in education (i'm a student) or its use in the industry.  I
went with a friend who also attended the conference from my school and
sat down expectantly.

I noticed the guy was trying to set up a powerproint (or OOo or
whatever) presentation and I simply couldnt believe it.  A powerpoint
presentation?  Pictures?  text?  preparation?  That doesn't sound like
lightning at all.  It sounds like, "slow-tning" talks.  Methodically
prepared sales-pitch presentations on johnny q. coder's latest
commercial triumph.  I thought these talks were spur of the moment,
community-delivered and off the cuff?

In my opinion, i don't believe that lightning talks should include the
option of using presentation software, maybe thats too restrictive,
but it seems to me that we'd be treated to much more grassroots or
user-given talks rather than sponsor-given ones.

I could just be ranting.


Number Two:  Presenters should be required to post their slides on the
web site / schedule before they are permitted to present.

We want 'em, they've got 'em, and I was in more than one session where
simply having uploaded them to the PyCon schedule would have saved the
presenters bacon when it came time for their laptop to die or
something else.

I realize that these presentations are fluid and change (often the
night before!) but a failsafe like this wouldn't hurt anyone.

Number Three:  Too much code, not enough concept.

Presenters this one's for you.  I can't count the number of
presentations I attended where the presenter would click through three
slides of pycode just to show us a two or three-line snippet that
illustrated their point.  Worse yet, it was often at the bottom of the
screen so no one but the front row could see it.  This goes for text
two.  I saw some great presentations as well, and they had limited
text on each slide.  The last thing your audience wants to see is a
slide drenched in text of any kind.

You only have 30 minutes (or less).  Show us brief couplets of code
for syntax sake.  We don't care about code, we care about the
concept.  If it were an hour lecture you could go through pages of
code and itd be great, but when we can't even read the whole slide
before you move on then its too much.

Number Four:  What's a BOF?

Noob here.  My first pycon and I didnt know the terminology.  Shocker
huh?  Heh, well i figured it out into the first day, but still didn't
quite get the concept.  Around day two or three i started attending
these and learned just how cool they are.

With the RAPID growth pycon has shown over the last few years, perhaps
a little session at the beginning to help the newcomers or a
"Terminology" page in the handbook would be helpful?


Praise
--

As a student attending his first pycon, i must say it was AWESOME.
Depending on the sessions i chose to attend, i learned all KINDS of
useful stuff.  Pyglet, Stackless (i'm willing to give it a chance
despite the mediocre presentation), RE, pysight and more.

Coming from a small school out west, the experience of visiting a
convention where a community actually existed was an incredible
experience.  That was probably the best part of the conference was
seeing that there truly was a programming community and meeting other
like-minded people and being able to finally discuss things of
programming importance with them.  I guess thats what we had hoped to
see more of in the lightning talks.

We enjoyed the EXPO as well and a couple of our graduating attendees
have nabbed phone interviews with companies that were represented
there.

I am definitely planning on returning to pycon next year, if only to
rub shoulders with other python programmers again and *hopefully*
attend a conference that has learned from any mistakes this year and
become an even better event for 2009.

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


Re: Can I run a python program from within emacs?

2008-03-20 Thread Jeff Schwab
Paulo da Costa wrote:

> People who say Emacs often mean GNU Emacs.

That's funny; to me, Emacs usually means XEmacs. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can I run a python program from within emacs?

2008-03-20 Thread Jeff Schwab
Grant Edwards wrote:
> On 2008-03-20, Jeff Schwab <[EMAIL PROTECTED]> wrote:
> 
 http://www.google.com/search?q=emacs+python
>>> Gee.  Thanks.
>> I believe Grant was suggesting that Emacs often serves a similar purpose 
>> on Unix to what Visual Studio does on Windows, which seemed to be what 
>> you were asking.  When asking about Mac OS X here, you are likely to get 
>> a lot of generic Unix responses.  (Would it have been clearer if he had 
>> just said "emacs?")
> 
> Don't the normal "run/debug python from inside emacs" methods
> work on OS-X?

AFAIK, yes; I don't see why it wouldn't.  I missed the word "emacs" in 
the subject header, and did not recognize "an emac" in the original post 
as meaning "emacs."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxFormBuilder

2008-03-20 Thread sturlamolden
On 20 Mar, 17:21, Stef Mientki <[EMAIL PROTECTED]>
wrote:

> I've tried several of the above mentioned builders,
> with the same result.
> I've also looked at wxFormBuilder,
> but I found it far too difficult and
> fully unreadable (how can you create actions/bindings on components you don't 
> see ?).
> So I might be very very naive,
> but why all so complex ??


Complex? Not at all! Let me show you an 'hello world!' example. Below
is the content of two files: HelloWorld.py hand-written be me, and
HelloWorld.xrc emitted by wxFormBuilder. I gave each control a care
about a name in wxFormBuilder, and use that to e.g. bind events and
load resources.





HelloWorld.py:

import wx
from wx import xrc
import sys

class MainFrame(object):

def __init__(self, xml):
self.xml = xml
self.frame = xml.LoadFrame(None,'MainFrame')
self.frame.Bind(wx.EVT_MENU, self.on_menu_exit,
id=xrc.XRCID('menuExit'))
self.frame.Bind(wx.EVT_BUTTON, self.on_say_hello,
id=xrc.XRCID('btnSayHello'))
self.frame.Show()

def on_say_hello(self, evt):
dlg = self.xml.LoadDialog(self.frame, 'HelloDialog')
dlg.ShowModal()
dlg.Destroy()

def on_menu_exit(self, evt):
self.frame.Destroy()
sys.exit(0)


class HelloWordApp(wx.App):

def OnInit(self):
xml = xrc.XmlResource('HelloWorld.xrc')
self.MainFrame = MainFrame(xml)
return True


if __name__ == '__main__':
app = HelloWordApp(0)
app.MainLoop()






HelloWorld.xrc:



http://www.wxwindows.org/wxxrc"; version="2.3.0.1">

wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL
289,171




File

Exit 





wxVERTICAL

1
wxEXPAND
5
0,0


0

wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL
5

Say hello
0



1
wxEXPAND
5
0,0




wxDEFAULT_DIALOG_STYLE
190,144


wxVERTICAL

1
wxEXPAND
5

wxVERTICAL

1
wxEXPAND
5
0,0


0

wxALIGN_CENTER|wxALL
5


14

swiss

normal

normal

0
Times New 
Roman

Hello 
World!



1
wxEXPAND
5
0,0




0
wxEXPAND | wxALL
5

wxLI_

zope and python 2.5.1

2008-03-20 Thread hberig
Hi,
I'm sorry if this is an off-topic message, but I didn't found other
group.
I've read some articles about Zope, and since I like very much python,
I would like to run a webserver application using Zope instead other
web application server. I've difficulties to install zope 3 and zope 2
on linux 2.6.20 (ubuntu distribution), python 2.5.1. What happen?? Is
there a simple way to fix it?

Thanks in advance!


---[ Trying install Zope 2 ]---
Configuring Zope installation

Testing for an acceptable Python interpreter...

Python version 2.5.1 found at /usr/bin/python

No suitable Python version found. You should install
Python version 2.4.4 before continuing.
Versions 2.4.3 2.4.2 also work, but not as optimally.

---[ Trying install Zope 3 ]---
zope3_quick_start/zope3/src/zope/interface/common/interfaces.py",
line 80, in 
   classImplements(OverflowWarning, IOverflowWarning)
NameError: name 'OverflowWarning' is not defined

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


Re: Import a file to namespace

2008-03-20 Thread Jeffrey Froman
Pedro Machado Santa wrote:

> import testpackage
> 
> class testClass():
> #...
> 
> testpackage.testClass =  testClass


This method should work fine. Modules are effectively singletons, so running
this code one time anywhere in your application will cause the changes to
appear in all references to the original module.


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

Re: URLError

2008-03-20 Thread Jim
On Mar 19, 6:50 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Wed, 19 Mar 2008 14:45:39 -0700, Jim wrote:
> > Program randomly aborts when looking up url. The program loop thru
> > 4000+ records looking
> > up ID via internet and returnshtmlcode which is used in subsequent
> > processing. The code
> > for looking-up record is below followed by abort details. Can anyone
> > help with catching the
> > abort before program aborts or provide code to automatically start
> > program?
>
> Yes. Wrap the offending code with a try...except loop, something similar
> to this.
>
> try:
> contents = urllib2.urlopen(url).read()
> except URLError, e:
> if e.errno == 10053:
> # "Software caused connection abort"
> response = raw_input(
> "Temporary failure, Skip/Halt/try Again?")
> response = response.lower().strip()
> if response in ('h', 'halt'):
> break
> elif response in ('a', 'again', 't', 'try', 'try again'):
> continue
> elif response in ('', 's', 'skip'):
> lines -= 1
> continue
> else:
> print "Unknown response, boo hiss to you!"
> raise
>
> --
> Steven

Thanks Steven for recommendation.

The program is my first and I'm not a programmer so it will take me
some time to get your recommendation to work. So far the program runs
after I added code based on your example but the program still aborts
and none of the code ("Temporary failure, Skip/Halt/try Again?" or
"Unknown response, boo hiss to you!") in your example is displayed. It
appears to abort in the imported module "urllib2" which is open
source. The code in urllib2 is way over my skill level.

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


Re: if __name__ == '__main__':

2008-03-20 Thread 7stud
On Mar 20, 10:21 am, "Simon Brunning" <[EMAIL PROTECTED]>
wrote:
> On Thu, Mar 20, 2008 at 4:12 PM, Bhagwat Kolde <[EMAIL PROTECTED]> wrote:
> > Hi,
> > I am new to the python and not getting meaning of following line,
>
> > if __name__ == '__main__':
> >       main()
>

The if statement is used to skip the code after the if statement in
certain situations.  If that if statement is in a file named test1.py,
and you issue this command:

$ python test1.py

then the code after the if statement will execute.  That's because
python assigns the string '__main__' to the variable __name__ when the
program starts

However, if you do this:

---
#test1.py
def my_func(num):
print num * 2


if __name__ == "__main__":
print "Testing my func:", my_func(10)



#test2.py
import test1

test1.my_func(5)

---

...and you issue the command:

$python test2.py

Then the code after the if statement in test1.py will not execute.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: zope and python 2.5.1

2008-03-20 Thread Diez B. Roggisch
hberig wrote:

> Hi,
> I'm sorry if this is an off-topic message, but I didn't found other
> group.
> I've read some articles about Zope, and since I like very much python,
> I would like to run a webserver application using Zope instead other
> web application server. I've difficulties to install zope 3 and zope 2
> on linux 2.6.20 (ubuntu distribution), python 2.5.1. What happen?? Is
> there a simple way to fix it?

apt-get install python2.4

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


Re: if __name__ == '__main__':

2008-03-20 Thread Bhagwat Kolde
Thanks all my problem cleared.
Bhagwat

On Thu, Mar 20, 2008 at 11:02 PM, 7stud <[EMAIL PROTECTED]> wrote:

> On Mar 20, 10:21 am, "Simon Brunning" <[EMAIL PROTECTED]>
> wrote:
> > On Thu, Mar 20, 2008 at 4:12 PM, Bhagwat Kolde <[EMAIL PROTECTED]>
> wrote:
> > > Hi,
> > > I am new to the python and not getting meaning of following line,
> >
> > > if __name__ == '__main__':
> > >   main()
> >
>
> The if statement is used to skip the code after the if statement in
> certain situations.  If that if statement is in a file named test1.py,
> and you issue this command:
>
> $ python test1.py
>
> then the code after the if statement will execute.  That's because
> python assigns the string '__main__' to the variable __name__ when the
> program starts
>
> However, if you do this:
>
> ---
> #test1.py
> def my_func(num):
>print num * 2
>
>
> if __name__ == "__main__":
>print "Testing my func:", my_func(10)
>
> 
>
> #test2.py
> import test1
>
> test1.my_func(5)
>
> ---
>
> ...and you issue the command:
>
> $python test2.py
>
> Then the code after the if statement in test1.py will not execute.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Bhagwat K
"Play hard or go home"
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: os.path.getsize() on Windows

2008-03-20 Thread Sean DiZazzo
On Mar 20, 6:42 am, Duncan Booth <[EMAIL PROTECTED]> wrote:
> Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> > On Wed, 19 Mar 2008 12:34:34 +, Duncan Booth wrote:
> >> By default Python on Windows allows you to open a file for reading
> >> unless you specify a sharing mode which prevents it:
>
> > But the OP is talking about another process having opened the file for
> > WRITING, not reading. It's that other process that has exclusive access,
> > and the OP was trying to determine when it was safe to attempt opening
> > the file according to whether or not it was still growing.
>
> No, unless the other process has specified that it wants exclusive access
> there is nothing stopping his process also opening the file. That's why he
> has to specify when he opens it that he wants exclusive access: then it
> doesn't matter what the other process does, he won't be able to open it
> until the other process has closed the file.
>
> This all of course assumes that the other process writes the file in one
> single atomic chunk. If it were to create it and then separately open and
> write to it then all bets are off.

Thanks for your input.

After trying again this morning, the file is opened for reading.  I
must have had some wonky permissions on that file, so the error method
won't work.  Trying to use the md5 technique won't work here either.
It takes quite awhile to run one md5, let alone two on a growing
file.  These files can be 20-50GB.

The overall idea is to be able to tell if a file has finished being
placed in a directory without any control over what is putting it
there.  If I'm in control of the process, I know I can put it in a
temp area, etc.  I use the method I mention in my original post
regularly without knowing how the file gets there, and was surprised
to see it didn't work on Windows.

In this case, there will be so few people touching the system, that I
think I can get away with having the copy be done from Unix, but it
would be nice to have a general way of knowing this on Windows.

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


Re: Import a file to namespace

2008-03-20 Thread Pedro Machado Santa
On Mar 20, 5:24 pm, Jeffrey Froman <[EMAIL PROTECTED]> wrote:
> This method should work fine. Modules are effectively singletons, so running
> this code one time anywhere in your application will cause the changes to
> appear in all references to the original module.

Yhea. I got it now. :) It already works. I wasn't putting the module
on my working dir.

(I created the module testpackageaddon.py and I did the "override" on
it, then imported it after the import testpackage on my working
script.)

Thanks.

Pedro Machado Santa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxFormBuilder

2008-03-20 Thread sturlamolden
On 20 Mar, 17:21, Stef Mientki <[EMAIL PROTECTED]>
wrote:

> I've tried several of the above mentioned builders,
> with the same result.
> I've also looked at wxFormBuilder,
> but I found it far too difficult and
> fully unreadable (how can you create actions/bindings on components you don't 
> see ?).
> So I might be very very naive,
> but why all so complex ??


It is not complex. I have posted a small 'Hello World!' howto on my
blog. It shows you how to bind events:

http://sturlamolden.blogspot.com/2008/03/howto-using-wxformbuilder-with-wxpython.html



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


Re: Can I run a python program from within emacs?

2008-03-20 Thread Paulo da Costa
Jeff Schwab wrote:
> Paulo da Costa wrote:
> 
>> People who say Emacs often mean GNU Emacs.
> 
> That's funny; to me, Emacs usually means XEmacs. :)

Which is often a cause of confusion.

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


Need help calling a proprietary C DLL from Python

2008-03-20 Thread Craig
I use a proprietary dll from Software Source (vbis5032.dll). I have
successfully used it from Visual Basic 6, Fujitsu Cobol and from Perl.
I would now like to use it from Python.

The following is the C++ prototype for one of the functions:
short FAR PASCAL VmxOpen(BSTR*Filespec,
 LPSHORT  lpLocatorSize,
 LPSHORT  lpOmode,
 LPHANDLE lphwmcb,
 BSTR*Password);

The following is some Python code I put together:
from ctypes import *
from ctypes.util import *
libc = cdll.msvcrt
printf = libc.printf
sprintf = libc.sprintf
print "\nVB/ISAM testing:"
fName = windll.oleaut32.SysAllocStringByteLen("s:\\msdb\\dcod\x00",
13)
printf ("fName = \x22%slx22\n", fName)
pw = windll.oleaut32.SysAllocStringByteLen("XYZ\x00", 4)
printf ("pw = \x22%slx22\n", pw)
CacheSize = c_long(0)
OpenMode = c_long(3)
vHandle = c_long(0)
p_vHandle = pointer(vHandle)
X = c_long(0)
printf ("Before - X = %d, CacheSize = %d, OpenMode = %d, vHandle = %d
\n", X, CacheSize, OpenMode, vHandle)
print "Ready to call (Library = " + find_library("vbis5032") + ") ..."

X = windll.vbis5032.VmxOpen(byref(fName), byref(CacheSize),
byref(OpenMode), byref(vHandle), byref(pw))

printf ("After - X = %d, CacheSize = %d, OpenMode = %d, vHandle = %d
\n", X, CacheSize, OpenMode, vHandle)

exit(0)


The following is the output from the Python code:
VB/ISAM testing:
fName = "s:\msdb\dcodlx22
pw = "XYZlx22
Before - X = 0, CacheSize = 0, OpenMode = 3, vHandle = 0
Ready to call (Library = C:\Windows\vbis5032.dll) ...
Traceback (most recent call last):
  File "C:\temp\test3.py", line 19, in 
X = windll.vbis5032.VmxOpen(byref(fName), byref(CacheSize),
byref(OpenMode),
 byref(vHandle), byref(pw))
TypeError: byref() argument must be a ctypes instance, not 'int'


I am neither a C++ nor a Python expert, but having already used this
dll from other languages, I know this should be possible. I am sure it
is just my lack of knowledge of Python.

Can anyone assist with this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pycon disappointment

2008-03-20 Thread Ed Leafe
On Mar 20, 2008, at 11:54 AM, [EMAIL PROTECTED] wrote:

> Number Three:  Too much code, not enough concept.
>
> Presenters this one's for you.  I can't count the number of
> presentations I attended where the presenter would click through three
> slides of pycode just to show us a two or three-line snippet that
> illustrated their point.  Worse yet, it was often at the bottom of the
> screen so no one but the front row could see it.  This goes for text
> two.  I saw some great presentations as well, and they had limited
> text on each slide.  The last thing your audience wants to see is a
> slide drenched in text of any kind.


This is good advice: simple slides serve as organization cues, but  
the content should come from the speaker. The worst case (only saw  
this twice at this year's PyCon) is when there is a text-heavy slide  
that the presenter simply reads. We can all read it ourselves! Your  
job is to elaborate on the topic.

I'd like to see two things regarding slides: first, if at all  
possible, set a limit on the percentage of the talk that can consist  
of slides. I would much rather see the presenter show actual  
demonstrations of what they're talking about than simply talking about  
it. If that's not possible, then in the session description, clearly  
state the % of the talk that will be slides. Perhaps there are people  
who like to sit in a room and watch long PowerPoint (-type)  
presentations, but I'm not one of them. Let's see some code! Let's see  
stuff working (and sometimes crashing!), and how changes affect the  
results. When I've presented at PyCon and other conferences, that's  
the part that I spend the most time on: preparing demonstrations. It's  
not easy to do; certainly much more difficult than creating a slide  
that sums up what the demo does. But it makes for a much more  
interesting session!

-- Ed Leafe



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


Re: Need help calling a proprietary C DLL from Python

2008-03-20 Thread sturlamolden
On 20 Mar, 19:09, Craig <[EMAIL PROTECTED]> wrote:

The culprit i here:

> Before - X = 0, CacheSize = 0, OpenMode = 3, vHandle = 0

This binds these names to Python ints, but byref expects C types.

Also observe that CacheSize and OpenMode should be c_short.





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


Re: Need help calling a proprietary C DLL from Python

2008-03-20 Thread Craig
On Mar 20, 2:29 pm, sturlamolden <[EMAIL PROTECTED]> wrote:
> On 20 Mar, 19:09, Craig <[EMAIL PROTECTED]> wrote:
>
> The culprit i here:
>
> > Before - X = 0, CacheSize = 0, OpenMode = 3, vHandle = 0
>
> This binds these names to Python ints, but byref expects C types.
>
> Also observe that CacheSize and OpenMode should be c_short.

I changed CacheSize and OpenMode to c_short, and commented out that
line producing the "Before" message, and the output is the same.

Further "tinkering" revealed that it is the byref on the fName and pw
that are causing the error.

The entire problem appears to be around the production of a BSTR and
the passing of pointers (byref) to the BSTR.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python to C/C++

2008-03-20 Thread Dan Stromberg
On Wed, 19 Mar 2008 10:24:16 -0700, Patrick Mullen wrote:

> (sorry michael, didn't mean to personal post
> 
> On Wed, Mar 19, 2008 at 9:24 AM, Michael Wieher wrote:
>  > I think py2exe does this, but it might be a bit bloated
> 
>  No, py2exe basically bundles the main script and the interpreter
>  together so it's easy to run and requires no python installation.
> 
>  Look into pyrex and pypy.  A mature translator doesn't exist.  Also
>  there is ctypes which goes in reverse letting you use more c from
>  python easily.

I believe pyrex allows you to write very python-like code but build a 
binary extension module from it that runs at nearly C speed.  ISTR it 
does generate .c files.

There's also shedskin, which I believe is a static python -> C++ 
translator that was written as part of google's summer of code.

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


Re: forkpty not working?

2008-03-20 Thread Dan Stromberg

If you google a bit, I believe you'll find one or more python modules for 
working with ssh.

Also, if you want to roll your own, the easiest way to get around the 
password requirement is to use ssh passwordless authentication using DSA 
or RSA public/private keypairs:

http://stromberg.dnsalias.org/~dstromberg/ssh-keys.html

As far as why the code below doesn't open your "it_worked" file - exec 
replaces the current process with the specified process - so the current 
process effectively goes away on exec.

On Thu, 20 Mar 2008 00:40:49 -0700, est wrote:

> Hello everyone. I am trying to write a bash/ssh wrapper in python so
> python scripts could interact with bash/ssh.
> 
> Because when input passwords to ssh it requires a tty rather than stdin
> pipe, so i have to use a pty module to do that.
> 
> I copied this snippet from this thread
> http://groups.google.com/group/comp.lang.python/browse_thread/
thread/6bbc3d36b4e6ff55/
> 
> def rcmd(user, rhost, pw, cmd):
> #Fork a child process, using a new pseudo-terminal as the
> child's controlling terminal.
> pid, fd = os.forkpty()
> # If Child; execute external process
> if pid == 0:
> os.execv("/bin/ssh", ["/bin/ssh", "-l", user, rhost] +
> cmd)
> x=open("it_worked.txt", "w") #output a file for test
> x.write("xxx")
> x.close()
> #if parent, read/write with child through file descriptor else:
> pause()
> #Get password prompt; ignore
> os.read(fd, 1000)
> pause()
> #write password
> os.write(fd, pw + "\n")
> pause()
> res = ''
> #read response from child process
> s = os.read(fd,1 )
> while s:
> res += s
> s = os.read(fd, 1)
> return res
> 
> As far as I can see the code is not working, when called the function
> rcmd() there is no file it_worked.txt spawned in the directory. I am
> n00b to POSIX, so anyone please give me some hint? what happened when
> os.forkpty()?

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


Issues with XMLTreeBuilder in cElementTree and ElementTree

2008-03-20 Thread Michael Becker
I had some xmls being output by an application whose formating did not
allow for easy editing by humans so I was trying to write a short
python app to pretty print xml files. Most of the data in these xml
files is in the attributes so I wanted each attribute on its own line.
I wrote a short app using xml.etree.ElementTree.XMLTreeBuilder(). To
my dismay the attributes were getting reordered. I found that the
implementation of XMLTreeBuilder did not make proper use of the
ordered_attributes attribute of the expat parser (which it defaults
to). The constructor sets ordered_attributes = 1 but then the
_start_list method iterates through the ordered list of attributes and
stores them in a dictionary! This is incredibly unintuitive and seems
to me to be a bug. I would recommend the following changes to
ElementTree.py:

class XMLTreeBuilder:
...
def _start_list(self, tag, attrib_in):
fixname = self._fixname
tag = fixname(tag)
attrib = []
if attrib_in:
for i in range(0, len(attrib_in), 2):
attrib.append((fixname(attrib_in[i]),
self._fixtext(attrib_in[i+1])))
return self._target.start(tag, attrib)

class _ElementInterface:
...

def items(self):
try:
return self.attrib.items()
except AttributeError:
return self.attrib

These changes would allow the user to take advantage of the
ordered_attributes attribute in the expat parser to use either ordered
or unorder attributes as desired. For backwards compatibility it might
be desirable to change XMLTreeBuilder to default to ordered_attributes
= 0. I've never submitted a bug fix to a python library so if this
seems like a real bug please let me know how to proceed.

Secondly, I found a potential issue with the cElementTree module. My
understanding (which could be incorrect) of python C modules is that
they should work the same as the python versions but be more
efficient. The XMLTreeBuilder class in cElementTree doesn't seem to be
using the same parser as that in ElementTree. The following code
illustrates this issue:

>>> import xml.etree.cElementTree
>>> t1=xml.etree.cElementTree.XMLTreeBuilder()
>>> t1._parser.ordered_attributes = 1
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: _parser
>>> import xml.etree.ElementTree
>>> t1=xml.etree.ElementTree.XMLTreeBuilder()
>>> t1._parser.ordered_attributes = 1

In case it is relevant, here is the version and environment
information:
[EMAIL PROTECTED]/tpdata/ossgw/config} $ python -V
Python 2.5.1
[EMAIL PROTECTED]/tpdata/ossgw/config} $ uname -a
SunOS localhost 5.10 Generic_118833-33 sun4u sparc SUNW,Netra-240
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What Programming Languages Should You Learn Next?

2008-03-20 Thread Donn Cave
In article <[EMAIL PROTECTED]>,
 Paul Rubin  wrote:

...
> I think it's easier to write complex code in Haskell because:
> 
>   1) it has a powerful static type system that lets you express
> important invariants and have them enforced at compile time.  This not
> only catches errors but helps you understand the program logic almost
> like running the code under a debugger does.  If you try to fill a gap
> by putting in a piece of the wrong shape, it just won't fit and the
> compiler will tell you what you really wanted.  On the other hand,
> most types are inferred by the compiler, so you don't need a lot of
> cumbersome declarations like in Java.

Worth repeating.

One of the perhaps surprising consequences, Haskell code can
be very easy to modify.  I've been fooling around with computer
programs for a couple decades, and I'm just getting used to the
idea that I can casually rewrite Haskell code and get the compiler
to find what I missed.  I have come to feel that the indiscipline
of dynamic typing in languages like Python leads to an intuitively
surprising rigidity.  Ten years ago I would cheerfully accept this,
given the meager and clumsy support for static typing in languages
like C++, but today, it makes me appreciate Haskell's potential
for complex projects.

   Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Floating-point support

2008-03-20 Thread Blubaugh, David A.
Would anyone know as to how to develop floating point support for the
MyHDL module?  Has anyone worked with any alternative versions of the
IEEE standard for floating -point?  Also, has anyone developed a
floating-point library for a module within the python environment in
order to execute numerical computations.  I would imagine since I am
translating python to verilog by using MyHDL , that I will have to
develop the floating-point support module in python source code as well
?? 
If I can develop this one feature from MyHDL, it would allow this module
to be fairly competitive with commercial products.  



Thanks,

David Blubaugh

This e-mail transmission contains information that is confidential and may be 
privileged. It is intended only for the addressee(s) named above. If you 
receive 
this e-mail in error, please do not read, copy or disseminate it in any manner. 
If you are not the intended recipient, any disclosure, copying, distribution or 
use of the contents of this information is prohibited. Please reply to the 
message immediately by informing the sender that the message was misdirected. 
After replying, please erase it from your computer system. Your assistance in 
correcting this error is appreciated.

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

Re: Pycon disappointment

2008-03-20 Thread Greg Lindstrom
,,,... Let's see some code! Let's see

> stuff working (and sometimes crashing!), and how changes affect the
> results. When I've presented at PyCon and other conferences, that's
> the part that I spend the most time on: preparing demonstrations. It's
> not easy to do; certainly much more difficult than creating a slide
> that sums up what the demo does. But it makes for a much more
> interesting session!
>
> -- Ed Leafe


Here, here!! (or is it hear, hear??).  I remember Ed's talk on Dabo a couple
of years ago (or was it last year?) because he was writing code while up in
front of the room.  "Here's how to do this" and then he would tweak various
aspects and show the results.  I can appreciate the need for slides, but I
also like seeing "code in action".

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

Re: Removal of tkinter from python 3.0? [was: Fate of the repr module inPy3.0]

2008-03-20 Thread Ron Provost
I would really hate to see Tkinter removed from 3.0.  Because it's part of 
the distribution and extremely easy to create simple GUIs I use it all the 
time.  Isn't Python supposed to be a "Batteries Included" language?  Can 
that be said anymore without a GUI library?  And do we want to drop Tkinter 
only now, when tk seems to finally be getting renewed attention after years 
of neglect?

- Original Message - 
From: "Daniel Fetchinson" <[EMAIL PROTECTED]>
To: 
Sent: Thursday, March 20, 2008 3:39 AM
Subject: Removal of tkinter from python 3.0? [was: Fate of the repr module 
inPy3.0]


>> Was looking at PEP 3108, http://www.python.org/dev/peps/pep-3108/ ,
>> and saw that the repr module was slated for vaporization. I've only
>> used the module a few times ever. I'm curious if the community wants
>> it kept around or whether it is considered clutter.
>>
>> The PEP is going to be finalized soon, so if you have issues with it,
>> they should be sent to the PEP author or brought up on the list,
>> http://mail.python.org/mailman/listinfo/stdlib-sig .
>
> Is it just me or others also think that it would be a major loss to
> remove tkinter from the python core? PEP 3108 starts off with:
>
> Each module to be removed needs to have a justification as to why it
> should no longer be distributed with Python.
>
> then goes on with,
>
> With so many other GUI options out there that are considered better
> than Tkinter, it might be best to remove Tkinter from the stdlib and
> make it an externally maintained package.
>
> I don't get it. There are many [insert your favorite software
> component] options outside of the python core that are considered
> better than the one coming with python, yet they don't get removed.
> All network servers for example could be thrown out because twisted is
> considered better. This just doesn't make sense to me. Tkinter is
> great for its purpose, typical use cases are creating a simple GUI
> composed of a couple of components only. You can nicely do this with
> tkinter and the large user base shows that it's a real need real
> people have. Sure, for fancy GUI stuff there are better options but
> for quick and simple things tkinter is just great. And last time I
> checked python comes with batteries included so why sould I need to
> search and download a third party package for such a common use case?
>
> Thoughts anyone?
>
> Cheers,
> Daniel
> -- 
> http://mail.python.org/mailman/listinfo/python-list 

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


RE: What Programming Languages Should You Learn Next?

2008-03-20 Thread Reedick, Andrew
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:python-
> [EMAIL PROTECTED] On Behalf Of Donn Cave
> Sent: Thursday, March 20, 2008 3:39 PM
> To: python-list@python.org
> Subject: Re: What Programming Languages Should You Learn Next?
> 
> 
> Worth repeating.
> 
> One of the perhaps surprising consequences, Haskell code can
> be very easy to modify.  I've been fooling around with computer
> programs for a couple decades, and I'm just getting used to the
> idea that I can casually rewrite Haskell code and get the compiler
> to find what I missed.  I have come to feel that the indiscipline
> of dynamic typing in languages like Python leads to an intuitively
> surprising rigidity.  Ten years ago I would cheerfully accept this,
> given the meager and clumsy support for static typing in languages
> like C++, but today, it makes me appreciate Haskell's potential
> for complex projects.
> 


Haskell does look interesting (especially in light of that one summer
job way back when doing a _lot_ of Lotus-123 spreadsheet programming.)
There's a Haskell wiki: http://www.haskell.org/


Quicksort in Haskell versus C is amazing:
http://www.haskell.org/haskellwiki/Introduction#What.27s_good_about_func
tional_programming.3F

Quicksort in Python inspired by Haskell's quicksort:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66473



*

The information transmitted is intended only for the person or entity to which 
it is addressed and may contain confidential, proprietary, and/or privileged 
material. Any review, retransmission, dissemination or other use of, or taking 
of any action in reliance upon this information by persons or entities other 
than the intended recipient is prohibited. If you received this in error, 
please contact the sender and delete the material from all computers. GA623


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


Haskell vs ??

2008-03-20 Thread Michael Wieher
Just to help clear up my own understanding of this discussion, this is
basically a language that obfuscates details and makes low-level decisions
in a "average-best" way, and thus allows for lazy people to write kind of
decent code quickly?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: A question about a metacharacter

2008-03-20 Thread ajaksu
On Mar 20, 8:19 am, igbt <[EMAIL PROTECTED]> wrote:
> However, if you don't enter anything the
> script works but if you enter a dot (.) the script does not work.

Have you tried it with other non-metacharacter values?

> sss = entryName.get_text()      # The script gets the text
>         if sss == "" or sss == ".":
>                 gtk.main_quit()        #The script finishes
>

Try adding this:
 else:
 print sss, type(sss)

Good luck!
Daniel
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >