Re: Best way to emulate ordered dictionary (like in PHP)?

2006-04-12 Thread Georg Brandl
pyGuy wrote:
> I am dealing with user profiles, which are simply a set of field-value
> pairs. I've tried to many things to list, but for one, I tried creating
> a wrapper class which inherits the dictionary and overrides the
> iterator. Unfortunately I don't understand iterators enough to get this
> working and before I waste any more time trying I figured I should
> check wether there is a better way. I have run into a similar problem
> once, and I resolved it by creating a wrapper class for the 'list'
> class which overides the get_item method, checks for string parameter,
> then accesses the appropriate item via a lookup 'list' contained within
> the class which maps the string parameter to the index number (eh, it
> just doesn't seem practical though). Now, I'e never used PHP, but
> apparently, it's dictionaries retain the order in which the items are
> entered and regurgitates them in that order when you iterate over them.
> That is exactly what I want, but can't seem to get in Python. Any help?

If you search Google for OrderedDict, you get more than enough code snippets.
There's also one in the Python Cookbook, at
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/438823

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


Tkinter vs PyGTK

2006-04-12 Thread JyotiC
I want to make a stand alone gui. Whose work is to get the diff options
from user and run a shell  script based on them.

I wanna know which one is better to use Tkinter or PyGTK, in terms of
efficiency and functionality.

I hv read about Tkinter, but it takes too much time to  load, is there
a way to make it faster.
Is all gui take more time to load, this is the first time i am making a
gui.
wIll PyGtk be faster.
Is there any other way of making a gui using python

Thanx in advance

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


Re: list.clear() missing?!?

2006-04-12 Thread Serge Orlov

Martin v. Löwis wrote:
> Felipe Almeida Lessa wrote:
> > I love benchmarks, so as I was testing the options, I saw something very
> > strange:
> >
> > $ python2.4 -mtimeit 'x = range(10); '
> > 100 loops, best of 3: 6.7 msec per loop
> > $ python2.4 -mtimeit 'x = range(10); del x[:]'
> > 100 loops, best of 3: 6.35 msec per loop
> > $ python2.4 -mtimeit 'x = range(10); x[:] = []'
> > 100 loops, best of 3: 6.36 msec per loop
> > $ python2.4 -mtimeit 'x = range(10); del x'
> > 100 loops, best of 3: 6.46 msec per loop
> >
> > Why the first benchmark is the slowest? I don't get it... could someone
> > test this, too?
>
> In the first benchmark, you need space for two lists: the old one and
> the new one; the other benchmarks you need only a single block of
> memory (*). Concluding from here gets difficult - you would have to study
> the malloc implementation to find out whether it works better in one
> case over the other. Could also be an issue of processor cache: one
> may fit into the cache, but the other may not.

Addition to the previous message. Now I follow you :) There are indeed
two arrays and cache seems to be the second reason for slowdown, but
iterating backwards is also contributing to slowdown.

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


Re: Tkinter vs PyGTK

2006-04-12 Thread Ravi Teja

JyotiC wrote:
> I want to make a stand alone gui. Whose work is to get the diff options
> from user and run a shell  script based on them.
>
> I wanna know which one is better to use Tkinter or PyGTK, in terms of
> efficiency and functionality.
>
> I hv read about Tkinter, but it takes too much time to  load, is there
> a way to make it faster.
> Is all gui take more time to load, this is the first time i am making a
> gui.
> wIll PyGtk be faster.
> Is there any other way of making a gui using python
>
> Thanx in advance

Speed is not the main concern. You won't notice any speed differences
in a small application like that.

Python has many ways of building a GUI.
http://wiki.python.org/moin/GuiProgramming
Everyone has their favorite(s). It is impossible to get a good opinion
on this. A GUI toolkit choice can be quite complex since there are many
variables. It is a decision you will have to make yourself.

If your needs are simple (just get a few options and not concerned
about layout details and other functionality), try something along the
lines of
http://wiki.woodpecker.org.cn/moin/EasyGuider

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


Re: executing perl script within python

2006-04-12 Thread Ravi Teja
This may help
http://search.cpan.org/~gaas/pyperl-1.0/perlmodule.pod

You can always use pipes (os.popen) to keep things simple.

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


Re: list.clear() missing?!?

2006-04-12 Thread Serge Orlov

Felipe Almeida Lessa wrote:
> Em Qua, 2006-04-12 às 11:36 +1000, Steven D'Aprano escreveu:
> > On Tue, 11 Apr 2006 19:15:18 +0200, Martin v. Löwis wrote:
> >
> > > Felipe Almeida Lessa wrote:
> > >> I love benchmarks, so as I was testing the options, I saw something very
> > >> strange:
> > >>
> > >> $ python2.4 -mtimeit 'x = range(10); '
> > >> 100 loops, best of 3: 6.7 msec per loop
> > >> $ python2.4 -mtimeit 'x = range(10); del x[:]'
> > >> 100 loops, best of 3: 6.35 msec per loop
> > >> $ python2.4 -mtimeit 'x = range(10); x[:] = []'
> > >> 100 loops, best of 3: 6.36 msec per loop
> > >> $ python2.4 -mtimeit 'x = range(10); del x'
> > >> 100 loops, best of 3: 6.46 msec per loop
> > >>
> > >> Why the first benchmark is the slowest? I don't get it... could someone
> > >> test this, too?
> > >
> > > In the first benchmark, you need space for two lists: the old one and
> > > the new one;
> >
> > Er, what new list? I see only one list, x = range(10), which is merely
> > created then nothing done to it. Have I missed something?
>
> He's talking about the garbage collector.

To be exact the reason for two array is timeit.py. It doesn't place the
code to time into a separate namespace but injects it into a for loop,
so the actual code timed is:
for _i in _it:
x = range(10)
and that makes two arrays with 100.000 items exist for a short time
starting from second iteration.

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


RE: Help needed on COM issue

2006-04-12 Thread Tim Golden
[Mike Howard]

| Should read ...
| I'm doing some conversion of vb code to python code and I have a
| problem with a COM object
| 
| Specifically in VB I can do
| Set oR = oA.Action
| debug.print oR.Item(1,2)
|  [returns say "1"]
| oR.Item(1,2)="4"
| debug.print oR
|  [returns "4"]
| oR.Update
|  [saves the record with the new item]
| 
| In Python I need to do ..
| 
| oR=oA.Action()
| print oR.Item(1,2)[0]
|  [returns say "1"]
| 
| But when I ty to update the value
| 
| oR.Item(1,2)[0]="4"
| 
| I get a TypeError : object doesn't support item assignment.

You sometimes find that altho' VB lets you shortcut attribute
value and assignment, it's actually doing a .Value= 
behind-the-scenes. (At least, I seem to remember coming across that).

So try something like:

oR.Item(1, 2)[0].Value = "4"

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: Best way to emulate ordered dictionary (like in PHP)?

2006-04-12 Thread pyGuy
Great, that recipe is exactly what I needed, and much cleaner than my
clumsy attempts. Thank you for your help.

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


A bug of httplib?

2006-04-12 Thread gcn
Hello,

The HTTPSConnection class in httplib overload the connect method of
HTTPConnection, but it can only deals with IPv4:

def connect(self):
"Connect to a host on a given (SSL) port."

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((self.host, self.port))
ssl = socket.ssl(self.sock, self.key_file, self.cert_file)
self.sock = FakeSocket(self.sock, ssl)

Is it a bug or I should use other method?

Thanks.

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


Beginner question. Exceptions

2006-04-12 Thread Jose Carlos Balderas Alberico
Hello. I'm having my way with exceptions in a little program I've done, and I'm wondering... What is a decent way of dealing with them? By a decent way I mean, what should I do when I see that an exception has occurred? I've seen that Python's default action is to print a stack trace. As far as I know, exception handling is a mean of knowing what can go wrong with your program, like anticipating wrongs and treating them.

 
What I'm having trouble understanding is this: if I use a "raise" sentence to raise an exception... shoul I use it inside a "try" block, so I can catch it with an "except" block? If I don't do that, a stack trace will be printed onto the screen... Is that the way it's usually done?

 
Please, help me out, for I'm kind of new to exceptions and I want to know if I get them right.
 
Thanks a lot in advance.
Jose Carlos.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: turning python-cgi into an html output

2006-04-12 Thread Gerard Flanagan

Kun wrote:
> i have a python cgi script that displays tables from a mysql database in
> html.
>
> the problem is, i want to use excel's web query to pull this data and
> the web query doesn't read .py files.
>
> thus i am wondering what is the easiest way to just turn my .py html
> output into a .html output.
> 

Have you tried using GET instead of POST in your form?

Gerard

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


Re: Tkinter vs PyGTK

2006-04-12 Thread Paul Rubin
"Ravi Teja" <[EMAIL PROTECTED]> writes:
> Speed is not the main concern. You won't notice any speed differences
> in a small application like that.

That's wishful thinking--even a totally trivial tkinter program has
noticable startup delay:

>>> from Tkinter import *
>>> a=Tk()

takes several seconds if the page cache isn't preloaded.  I doubt
PyGTK is any faster, though.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A question about the urllib2 ?

2006-04-12 Thread Bo Yang
Fuzzyman 写道:
> Bo Yang wrote:
>   
>> Hi ,
>> Recently I use python's urllib2 write a small script to login our
>> university gateway .
>> Usually , I must login into the gateway in order to surf the web . So ,
>> every time I
>> start my computer , it is my first thing to do that open a browser to
>> login the gateway !
>>
>> So , I decide to write such a script , sending some post information to
>> the webserver
>> directly to login automatic once the computer is on . And I write the
>> code below :
>>
>> urllib2.urlopen(urllib2.Request(url="https://202.113.16.223/php/user_login.php";,
>> data="loginuser=0312889&password=o127me&domainid=1&refer=1& logintype=
>> #"))
>>
>> In the five '#' above , I must submit some Chinese character , but the
>> urllib2 complain
>> for the non-ascii characters .
>>
>> What do you think this ?
>>
>> 
> I haven't tried this, so I'm guessing :-)
>
> Do you pass in the string to urllib2 as unicode ? If so, try encoding
> it to UTF8 first...
>
> Otherwise you might try escaping it using ``urllib.quote_plus``. (Note
> ``urllib``, *not* ``urllib2``.)
>
> All the best,
>
> Fuzzyman
> http://www.voidspace.org.uk/python/index.shtml
>
>   
>> Any help will be appreciated very much , thanks in advance !
>> 
>
>   
Thank you , I have got it !
I quote the Chinese with urllib.quote() ,
Thanks again !
-- 
http://mail.python.org/mailman/listinfo/python-list

Web Service SOAP - Unknown element v1

2006-04-12 Thread Jesus . Javier . Masa . Lledo

This is the result of calling:
>>>servidor.soapproxy.config.dumpSOAPOut = True
>>>servidor.soapproxy.config.dumpSOAPIn = True
>>> servidor.setDVD(title="BenHur")

*** Outgoing SOAP **


  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsd="http://www.w3.org/1999/XMLSchema"
>


BENHUR




*** Incoming SOAP **

e:ServerUnknown element tituloorg.idoox.xmlrpc.MessageProcessingException: Unknown element titulo
        at org.idoox.wasp.wsdl.SOAPMethodInfo$RequiredElements$Invocation.notNillElement(SOAPMethodInfo.java:1033)
        at com.systinet.wasp.server.adaptor.JavaInvoker.fillCallParamsXml(JavaInvoker.java:1162)
        at com.systinet.wasp.server.adaptor.JavaInvoker.beginInvoke(JavaInvoker.java:491)
        at com.idoox.wasp.server.adaptor.JavaAdaptorImpl.beginInvoke(JavaAdaptorImpl.java:63)
        at com.idoox.wasp.server.AdaptorTemplate.javaInvocation(AdaptorTemplate.java:514)
        at com.idoox.wasp.server.AdaptorTemplate.doDispatch(AdaptorTemplate.java:395)
        at com.idoox.wasp.server.AdaptorTemplate.dispatch(AdaptorTemplate.java:328)
        at com.idoox.wasp.server.ServiceConnector.dispatch(ServiceConnector.java:390)
        at com.systinet.wasp.ServiceManagerImpl.dispatchRequest(ServiceManagerImpl.java:626)
        at com.systinet.wasp.ServiceManagerImpl.dispatch(ServiceManagerImpl.java:461)
        at com.systinet.wasp.ServiceManagerImpl$DispatcherConnHandler.handlePost(ServiceManagerImpl.java:2562)
        at com.idoox.transport.http.server.Jetty$WaspHttpHandler.handle(Jetty.java:97)
        at com.mortbay.HTTP.HandlerContext.handle(HandlerContext.java:1087)
        at com.mortbay.HTTP.HttpServer.service(HttpServer.java:675)
        at com.mortbay.HTTP.HttpConnection.service(HttpConnection.java:457)
        at com.mortbay.HTTP.HttpConnection.handle(HttpConnection.java:317)
        at com.mortbay.HTTP.SocketListener.handleConnection(SocketListener.java:99)
        at com.mortbay.Util.ThreadedServer.handle(ThreadedServer.java:254)
        at com.mortbay.Util.ThreadPool$PoolThreadRunnable.run(ThreadPool.java:607)
        at java.lang.Thread.run(Thread.java:534)

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

Re: Tkinter vs PyGTK

2006-04-12 Thread Ravi Teja
Not from here.
A highly unscientific measurement, using execution time from SciTe on
my 3.5 yr old box.

Python startup - 0.272 sec
With your snippet for Tk - 0.402 sec

0.13 sec is trivial in my book.

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


UDP max datagram size

2006-04-12 Thread Iain King
Hi.  I've been looking everywhere for this and can't find it, apologies
if I'm being obtuse:  How do I set the max datagram packet size?  I'm
using the socket module.  It seem like it's hardcoded at 255, but I
need it to be larger.

Iain

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


Re: About classes and OOP in Python

2006-04-12 Thread bruno at modulix
Ben C wrote:
> On 2006-04-11, Michele Simionato <[EMAIL PROTECTED]> wrote:
> 
>>Roy Smith wrote:
>>
>>
>>>That being said, you can indeed have private data in Python.  Just prefix
>>>your variable names with two underscores (i.e. __foo), and they effectively
>>>become private.  Yes, you can bypass this if you really want to, but then
>>>again, you can bypass private in C++ too.
> 
> 
>>Wrong, _foo is a *private* name (in the sense "don't touch me!"), __foo
>>on the contrary is a *protected* name ("touch me, touch me, don't worry
>>I am protected against inheritance!").
>>This is a common misconception, I made the error myself in the past.
> 
> 
> Please explain! I didn't think _foo meant anything special,

It doesn't mean anything special in the language itself - it's a
convention between programmers. Just like ALL_CAPS names is a convention
for (pseudo) symbolic constants. Python relies a lot on conventions.

> __foo
> expands to _classname__foo for some sort of name-hiding. 

s/hiding/mangling/

> What am I
> missing?

the __name_mangling mechanism is meant to protect some attributes to be
*accidentaly* overridden. It's useful for classes meant to be subclassed
(ie in a framework). It has nothing to do with access restriction - you
still can access such an attribute.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A question about the urllib2 ?

2006-04-12 Thread Serge Orlov

Bo Yang wrote:
> Hi ,
> Recently I use python's urllib2 write a small script to login our
> university gateway .
> Usually , I must login into the gateway in order to surf the web . So ,
> every time I
> start my computer , it is my first thing to do that open a browser to
> login the gateway !
>
> So , I decide to write such a script , sending some post information to
> the webserver
> directly to login automatic once the computer is on . And I write the
> code below :
>
> urllib2.urlopen(urllib2.Request(url="https://202.113.16.223/php/user_login.php";,
> data="loginuser=0312889&password=o127me&domainid=1&refer=1& logintype=
> #"))
>
> In the five '#' above , I must submit some Chinese character , but the
> urllib2 complain
> for the non-ascii characters .

I guess the server expect that a browser is coming from page
https://202.113.16.223/, so the url should be submitted in the encoding
of page https://202.113.16.223/ which is gb2312.

urllib2.urlopen(urllib2.Request(url="https://202.113.16.223/php/user_login.php";,
data=u"loginuser=0312889&password=o127me&domainid=1&refer=1& logintype=
写道".encode('gb2312')))

should work

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

Re: About classes and OOP in Python

2006-04-12 Thread bruno at modulix
Casey Hawthorne wrote:
>>I think it's important not to wrongly confuse 'OOP' with ''data hiding'
>>or any other aspect you may be familiar with from Java or C++. The
>>primary concept behind OOP is not buzzwords such as abstraction,
>>encapsulation, polymorphism, etc etc, but the fact that your program
>>consists of objects maintaining their own state, working together to
>>produce the required results, as opposed to the procedural method where
>>the program consists of functions that operate on a separate data set.
> 
> 
> Isn't "inheritance" an important buzzword for OOP?

Which kind of inheritance ? subtyping or implementation inheritance ?-)

FWIW, subtyping is implicit in dynamically typed languages, so they
don't need support for such a mechanism. And implementation inheritance
is not much more than a special case of composition/delegation, so it's
almost useless in a language that have a good support for delegation
(which we have in Python, thanks to __getattr__/__setattr__).


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter vs PyGTK

2006-04-12 Thread Paul Rubin
"Ravi Teja" <[EMAIL PROTECTED]> writes:
> A highly unscientific measurement, using execution time from SciTe on
> my 3.5 yr old box.
> 
> Python startup - 0.272 sec
> With your snippet for Tk - 0.402 sec

What OS?  Try rebooting the box (to clear cache) and measuring again?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UDP max datagram size

2006-04-12 Thread Heiko Wundram
Am Mittwoch 12 April 2006 10:26 schrieb Iain King:
> Hi.  I've been looking everywhere for this and can't find it, apologies
> if I'm being obtuse:  How do I set the max datagram packet size?  I'm
> using the socket module.  It seem like it's hardcoded at 255, but I
> need it to be larger.

The minimal size any IP-stack has to be able to handle is 512 bytes. Normally, 
modern IP stacks will handle packets up to 4096 bytes and possibly larger 
packets (with correct fragmentation and rejoining). But this depends on the 
IP stack that's used to send and to receive the packet.

Anyway, a maximum size of 255 bytes is certainly not true for UDP packets.

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


Re: UDP max datagram size

2006-04-12 Thread Iain King

Heiko Wundram wrote:
> Am Mittwoch 12 April 2006 10:26 schrieb Iain King:
> > Hi.  I've been looking everywhere for this and can't find it, apologies
> > if I'm being obtuse:  How do I set the max datagram packet size?  I'm
> > using the socket module.  It seem like it's hardcoded at 255, but I
> > need it to be larger.
>
> The minimal size any IP-stack has to be able to handle is 512 bytes. Normally,
> modern IP stacks will handle packets up to 4096 bytes and possibly larger
> packets (with correct fragmentation and rejoining). But this depends on the
> IP stack that's used to send and to receive the packet.
>
> Anyway, a maximum size of 255 bytes is certainly not true for UDP packets.
> 
> --- Heiko.

Yep, I was just being dumb.  Thanks anyway.

Iain

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


Problem with spawning an external process

2006-04-12 Thread Nico Kruger

I want to execute a command (in this case, and it seems to be
significant, a Java program) in a thread in Python. When I execute the
java binary in the main python thread, everything runs correctly. But
when I try and execute java in a thread, java segfaults. I am using
Python 2.3.3 and trying to run the java binary from the 1.4.2 SDK from
Sun.

I have tried executing some arbitrary C program that I wrote, and it
works fine in the main thread and the started thread. The problem seems
to be specific to the Java binary.

Here is the example code:

--- START CODE ---
import os
import popen2
import time
import select
import threading

# Change these to suit your system
PATH = '/home/nico/j2sdk1.4.2/bin/java'
#PATH = '/home/nico/j2sdk1.4.2/bin/java -invalid_arg'

def get_ret(status):
signal = status & 0xff
if signal == 0:
retcode = status >> 8
else:
retcode = 0
return signal,retcode

print "In main thread"
# Using spawn
pid = os.spawnl(os.P_NOWAIT,PATH,PATH)
ret = os.waitpid(pid,0)
print "PID: %i  signal: %i   return code: %i" %
(ret[0],get_ret(ret[1])[0],get_ret(ret[1])[1])

class TestThread(threading.Thread):
def run(self):
# Using spawn
pid = os.spawnl(os.P_NOWAIT,PATH,PATH)
ret = os.waitpid(pid,0)
print "PID: %i  signal: %i   return code: %i" %
(ret[0],get_ret(ret[1])[0],get_ret(ret[1])[1])

print "In Thread"
TestThread().start()

print "Waiting..."
time.sleep(2)
print "...Finished"
 END CODE 

Here is the output that I get on my machine:
[nico@ script]$ python testcrash2.py
In main thread
   
PID: 32107  signal: 0   return code: 1
In Thread
PID: 32116  signal: 11   return code: 0


You will notice that in the main thread, the program executes correctly
(return code 1, signal 0). When the command is executed in the thread,
it segfaults (signal 11). The second PATH= line calls Java with an
invalid argument. In this case, it does not crash in the thread.

I have tried a fork() and then os.execv in the thread as well, and get
the same behaviour.

I would appreciate it if someone with both Java and Python could try and
run this sample and report back. Any suggestions would be welcome, as
this is quite the showstopper for me at the moment. I am sure I am
missing something totally obvious...

Thanks in advance,
Nico.


--
NetSys International (Pty) Ltd.
Tel : +27 12 349 2056
Fax : +27 12 349 2757
Web : http://www.netsys.co.za
P.O. Box 35798, Menlo Park, 0102, South Africa


The information contained in this communication is confidential and may be
legally privileged. It is solely for use of the individual or entity to whom
is addressed and others authorised to receive it. If you are not the intended
recipient you are hereby notified that any disclosure, copying, distribution
or taking of any action in reliance on the contents of this information is
strictly prohibited and may be unlawful.

This Message has been scanned for viruses and dangerous content by the NetSys
International Mail Scanner and is believed to be clean.

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


Re: Problem with spawning an external process

2006-04-12 Thread Nico Kruger
Apologies, this is on a Fedora Core 2 system.

On Wed, 2006-04-12 at 11:27, Nico Kruger wrote:
> I want to execute a command (in this case, and it seems to be
> significant, a Java program) in a thread in Python. When I execute the
> java binary in the main python thread, everything runs correctly. But
> when I try and execute java in a thread, java segfaults. I am using
> Python 2.3.3 and trying to run the java binary from the 1.4.2 SDK from
> Sun.
> 
> I have tried executing some arbitrary C program that I wrote, and it
> works fine in the main thread and the started thread. The problem seems
> to be specific to the Java binary.
> 
> Here is the example code:
> 
> --- START CODE ---
> import os
> import popen2
> import time
> import select
> import threading
> 
> # Change these to suit your system
> PATH = '/home/nico/j2sdk1.4.2/bin/java'
> #PATH = '/home/nico/j2sdk1.4.2/bin/java -invalid_arg'
> 
> def get_ret(status):
>   signal = status & 0xff
>   if signal == 0:
>   retcode = status >> 8
>   else:
>   retcode = 0
>   return signal,retcode
>   
> print "In main thread"
> # Using spawn
> pid = os.spawnl(os.P_NOWAIT,PATH,PATH)
> ret = os.waitpid(pid,0)
> print "PID: %i  signal: %i   return code: %i" %
> (ret[0],get_ret(ret[1])[0],get_ret(ret[1])[1])
> 
> class TestThread(threading.Thread):
>   def run(self):
>   # Using spawn
>   pid = os.spawnl(os.P_NOWAIT,PATH,PATH)
>   ret = os.waitpid(pid,0)
>   print "PID: %i  signal: %i   return code: %i" %
> (ret[0],get_ret(ret[1])[0],get_ret(ret[1])[1])
>   
> print "In Thread"
> TestThread().start()
> 
> print "Waiting..."
> time.sleep(2)
> print "...Finished"
>  END CODE 
> 
> Here is the output that I get on my machine:
> [nico@ script]$ python testcrash2.py
> In main thread
>
> PID: 32107  signal: 0   return code: 1
> In Thread
> PID: 32116  signal: 11   return code: 0
> 
> 
> You will notice that in the main thread, the program executes correctly
> (return code 1, signal 0). When the command is executed in the thread,
> it segfaults (signal 11). The second PATH= line calls Java with an
> invalid argument. In this case, it does not crash in the thread.
> 
> I have tried a fork() and then os.execv in the thread as well, and get
> the same behaviour.
> 
> I would appreciate it if someone with both Java and Python could try and
> run this sample and report back. Any suggestions would be welcome, as
> this is quite the showstopper for me at the moment. I am sure I am
> missing something totally obvious...
> 
> Thanks in advance,
> Nico.
> 



--
NetSys International (Pty) Ltd.
Tel : +27 12 349 2056
Fax : +27 12 349 2757
Web : http://www.netsys.co.za
P.O. Box 35798, Menlo Park, 0102, South Africa


The information contained in this communication is confidential and may be
legally privileged. It is solely for use of the individual or entity to whom
is addressed and others authorised to receive it. If you are not the intended
recipient you are hereby notified that any disclosure, copying, distribution
or taking of any action in reliance on the contents of this information is
strictly prohibited and may be unlawful.

This Message has been scanned for viruses and dangerous content by the NetSys
International Mail Scanner and is believed to be clean.

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


Re: Problem with spawning an external process

2006-04-12 Thread Daniel Nogradi
> > I want to execute a command (in this case, and it seems to be
> > significant, a Java program) in a thread in Python. When I execute the
> > java binary in the main python thread, everything runs correctly. But
> > when I try and execute java in a thread, java segfaults. I am using
> > Python 2.3.3 and trying to run the java binary from the 1.4.2 SDK from
> > Sun.
> > Here is the output that I get on my machine:
> > [nico@ script]$ python testcrash2.py
> > In main thread
> >
> > PID: 32107  signal: 0   return code: 1
> > In Thread
> > PID: 32116  signal: 11   return code: 0


Your code works fine here both in the main and the new thread. Here is
the output:

In main thread

PID: 5990  signal: 0   return code: 1
In Thread

Waiting...PID: 5999  signal: 0   return code: 1
...Finished

So I guess the problem is somewhere else.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with spawning an external process

2006-04-12 Thread Daniel Nogradi
> > > I want to execute a command (in this case, and it seems to be
> > > significant, a Java program) in a thread in Python. When I execute the
> > > java binary in the main python thread, everything runs correctly. But
> > > when I try and execute java in a thread, java segfaults. I am using
> > > Python 2.3.3 and trying to run the java binary from the 1.4.2 SDK from
> > > Sun.
> > > Here is the output that I get on my machine:
> > > [nico@ script]$ python testcrash2.py
> > > In main thread
> > >
> > > PID: 32107  signal: 0   return code: 1
> > > In Thread
> > > PID: 32116  signal: 11   return code: 0
>
>
> Your code works fine here both in the main and the new thread. Here is
> the output:
>
> In main thread
> 
> PID: 5990  signal: 0   return code: 1
> In Thread
> 
> Waiting...PID: 5999  signal: 0   return code: 1
> ...Finished
>
> So I guess the problem is somewhere else.

And I should have also added that this is with python 2.4, java 1.4.2, suse 9.3.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with spawning an external process

2006-04-12 Thread Nico Kruger
Daniel, thanks for your input. What version of the JDK/JRE and Python
are you using?

On Wed, 2006-04-12 at 11:53, Daniel Nogradi wrote:
> > > I want to execute a command (in this case, and it seems to be
> > > significant, a Java program) in a thread in Python. When I execute the
> > > java binary in the main python thread, everything runs correctly. But
> > > when I try and execute java in a thread, java segfaults. I am using
> > > Python 2.3.3 and trying to run the java binary from the 1.4.2 SDK from
> > > Sun.
> > > Here is the output that I get on my machine:
> > > [nico@ script]$ python testcrash2.py
> > > In main thread
> > >
> > > PID: 32107  signal: 0   return code: 1
> > > In Thread
> > > PID: 32116  signal: 11   return code: 0
> 
> 
> Your code works fine here both in the main and the new thread. Here is
> the output:
> 
> In main thread
> 
> PID: 5990  signal: 0   return code: 1
> In Thread
> 
> Waiting...PID: 5999  signal: 0   return code: 1
> ...Finished
> 
> So I guess the problem is somewhere else.
-- 
Regards,
Nico.


--
NetSys International (Pty) Ltd.
Tel : +27 12 349 2056
Fax : +27 12 349 2757
Web : http://www.netsys.co.za
P.O. Box 35798, Menlo Park, 0102, South Africa


The information contained in this communication is confidential and may be
legally privileged. It is solely for use of the individual or entity to whom
is addressed and others authorised to receive it. If you are not the intended
recipient you are hereby notified that any disclosure, copying, distribution
or taking of any action in reliance on the contents of this information is
strictly prohibited and may be unlawful.

This Message has been scanned for viruses and dangerous content by the NetSys
International Mail Scanner and is believed to be clean.

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


Re: About classes and OOP in Python

2006-04-12 Thread Magnus Lycka
Michele Simionato wrote:
> Roy Smith wrote:
> 
>> That being said, you can indeed have private data in Python.  Just prefix
>> your variable names with two underscores (i.e. __foo), and they effectively
>> become private.  Yes, you can bypass this if you really want to, but then
>> again, you can bypass private in C++ too.
> 
> Wrong, _foo is a *private* name (in the sense "don't touch me!"), __foo
> on the contrary is a *protected* name ("touch me, touch me, don't worry
> I am protected against inheritance!").
> This is a common misconception, I made the error myself in the past.

While your wording makes sense, it's probably confusing for anyone
with a C++ background, where private roughly means "only accessible
within the actual class" and protected roughly means "only accessible
within the class and other classes derived from it".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Decorators, Identity functions and execution...

2006-04-12 Thread Peter Hansen
Lawrence D'Oliveiro wrote:
> In article <[EMAIL PROTECTED]>,
>  "Ben Sizer" <[EMAIL PROTECTED]> wrote:
>>Every day I come across people or programs that use tab stops every 2
>>or 8 columns. I am another fan of tabs every 4 columns, but
>>unfortunately this isn't standard, so spaces in Python it is.
> 
> All we have to do is keep using and promoting 4-column tabs every chance 
> we get. I've been using them myself for about 18 years. Eventually 
> they'll become accepted as the standard.

"I am Lawrence of Borg.  You will be tabulated.  Resistance is futile."

:-)

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


Re: I meet problems while using the py2exe,Please help me!

2006-04-12 Thread Fulvio
Alle 10:17, mercoledì 12 aprile 2006, boyeestudio ha scritto:
> What is wrong with this problem

makes sense talking about the path on where cairo reside?

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


Re: Newbie wxPython questions.

2006-04-12 Thread bieliza
And why don´t you use Pythoncard, it takes the headache out of messing
with wxPyhthon

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


Re: Problem with spawning an external process

2006-04-12 Thread Daniel Nogradi
> Daniel, thanks for your input. What version of the JDK/JRE and Python
> are you using?

So the previous test was on python 2.4, java 1.4.2, suse 9.3 but now I
ran it on python 2.3.5, java 1.4.2, gentoo 1.4.16 and your code still
does what it supposed to do. I'm not sure if that is good new for you
though :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode, command-line and idle

2006-04-12 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
> Hello again, I've investigated a little bit and this is what I found:
> 
> If I run IDLE and type
> 
 import sys
 sys.stdin.encoding
> 
> I get
> 
> 'cp1252'
> 
> But if I have a whatever.py file (it can even be a blank file), I edit
> it with IDLE, I press F5 (Run Module) and then type:
> 
 import sys
 sys.stdin.encoding
> 
> I get
> 
> Traceback (most recent call last):
>   File "", line 1, in ?
> sys.stdin.encoding
> AttributeError: PyShell instance has no attribute 'encoding'
> 
> So when I have the following code in a file:
> 
> # -*- coding: cp1252 -*-
> import sys
> text1 = u'españa'
> text2 = unicode(raw_input(), sys.stdin.encoding)
> if text1 == text2:
> print 'same'
> else:
> print 'not same'
> 
> and I press F5 (Run Module) I get:
> 
> Traceback (most recent call last):
>   File "C:\test.py", line 4, in ?
> text2 = unicode(raw_input(), sys.stdin.encoding)
> AttributeError: PyShell instance has no attribute 'encoding'
> 
> This same code works if I just double-click it (run it in the windows
> console) instead of using IDLE.
> 
> I'm using Python 2.4.3 and IDLE 1.1.3.

FWIW all of the above give me 'cp1252', not AttributeError, and the type 
of sys.stdin on my system is idlelib.rpc.RPCProxy, not PyShell.

Python 2.4.3 and IDLE 1.1.3 on Win2k

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


Re: the mysql for python cann't be install from the source! Help!!

2006-04-12 Thread Fulvio
Alle 22:24, martedì 11 aprile 2006, boyeestudio ha scritto:
> I search the mysql directory but gain none of it!

In the version MySQL-python-1.2.0 there isn't such file.
Better you re-read README file inside the tarball or zip file.

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


Re: Problem with spawning an external process

2006-04-12 Thread Nico Kruger
Daniel, you are correct, it is not that good news for me :)

But anyway, thanks to your responses, I installed Python 2.4.3 and it is
working on my machine now as well. We were overdue for an upgrade to our
Python environment anyways, so I think this is the final incentive to
upgrade.

Although, I will download 2.3.5 now and get back to you with the status.
Would be interesting to know when exactly this problem was fixed, maybe
it would help to know what is causing the problem? It really is a
strange one.

Again, thanks for your effort!


On Wed, 2006-04-12 at 12:41, Daniel Nogradi wrote:
> > Daniel, thanks for your input. What version of the JDK/JRE and Python
> > are you using?
> 
> So the previous test was on python 2.4, java 1.4.2, suse 9.3 but now I
> ran it on python 2.3.5, java 1.4.2, gentoo 1.4.16 and your code still
> does what it supposed to do. I'm not sure if that is good new for you
> though :)



--
NetSys International (Pty) Ltd.
Tel : +27 12 349 2056
Fax : +27 12 349 2757
Web : http://www.netsys.co.za
P.O. Box 35798, Menlo Park, 0102, South Africa


The information contained in this communication is confidential and may be
legally privileged. It is solely for use of the individual or entity to whom
is addressed and others authorised to receive it. If you are not the intended
recipient you are hereby notified that any disclosure, copying, distribution
or taking of any action in reliance on the contents of this information is
strictly prohibited and may be unlawful.

This Message has been scanned for viruses and dangerous content by the NetSys
International Mail Scanner and is believed to be clean.

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


Can't connect to SimpleXMLRPCServer. Help needed.

2006-04-12 Thread Jose Carlos Balderas Alberico
Up till now I've been setting up my server and client in the same machine, using the "localhost" address for everything.
Once I've made it work, I need to move my client application to the computer where it'll be run from, and for some reason, I get a socket.error: (111, 'connection refused').
 
The server is listening on port 8000. I've used the line 
 
server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000), )
##register functions...
...
...
server.serve_forever()
 
 
And the client does the following:
 
host = ":8000" (where  is the server's IP address)
conn = xmlrpclib.connect(host)
data = "" (requestData is a function previously registered in the server)
 
I've made sure the server is listening on port 8000, since the netstat command says it's listening on port 8000.
I've also pinged the server from the client and viceversa and I get an answer. So they can see each other.
 
I've tried looking in google but couldn't find a solution to this problem. Anyone can give me a hand on this?
Thank you very much.
 
Jose Carlos.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: list.clear() missing?!?

2006-04-12 Thread Steven D'Aprano
On Wed, 12 Apr 2006 00:33:29 -0700, Serge Orlov wrote:

> 
> Felipe Almeida Lessa wrote:
>> Em Qua, 2006-04-12 às 11:36 +1000, Steven D'Aprano escreveu:
>> > On Tue, 11 Apr 2006 19:15:18 +0200, Martin v. Löwis wrote:
>> >
>> > > Felipe Almeida Lessa wrote:
>> > >> I love benchmarks, so as I was testing the options, I saw something very
>> > >> strange:
>> > >>
>> > >> $ python2.4 -mtimeit 'x = range(10); '
>> > >> 100 loops, best of 3: 6.7 msec per loop
>> > >> $ python2.4 -mtimeit 'x = range(10); del x[:]'
>> > >> 100 loops, best of 3: 6.35 msec per loop
>> > >> $ python2.4 -mtimeit 'x = range(10); x[:] = []'
>> > >> 100 loops, best of 3: 6.36 msec per loop
>> > >> $ python2.4 -mtimeit 'x = range(10); del x'
>> > >> 100 loops, best of 3: 6.46 msec per loop
>> > >>
>> > >> Why the first benchmark is the slowest? I don't get it... could someone
>> > >> test this, too?
>> > >
>> > > In the first benchmark, you need space for two lists: the old one and
>> > > the new one;
>> >
>> > Er, what new list? I see only one list, x = range(10), which is merely
>> > created then nothing done to it. Have I missed something?
>>
>> He's talking about the garbage collector.
> 
> To be exact the reason for two array is timeit.py. It doesn't place the
> code to time into a separate namespace but injects it into a for loop,
> so the actual code timed is:
> for _i in _it:
> x = range(10)
> and that makes two arrays with 100.000 items exist for a short time
> starting from second iteration.

But that is precisely the same for the other timeit tests too.

for _i in _it:
x = range(10)
del x[:]

etc.

The question remains -- why does it take longer to do X than it takes to
do X and then Y?


-- 
Steven.

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

datetime: the date of the day one month ago...how?

2006-04-12 Thread gabor
hi,

i'm trying to get the date of the day one month ago.

for example:

today = 12.apr.2006
one-month-ago = 12.mar.2006

so:

one-month-ago(12.apr.2006) = 12.mar.2006

of course sometimes it gets more complicated, like:

one-month-ago(31.mar.2006)

or

one-month-ago(1.jan.2006)

the datetime.timedelta objects only work with hours or days or weeks, 
not month (i understand why)...

but is there a way to calculate this in python?

i really don't want to calculate it by myself :-))

thanks,
gabor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About classes and OOP in Python

2006-04-12 Thread bruno at modulix
Gregor Horvath wrote:
> Steven D'Aprano schrieb:
> 
> 
>>I don't know of many other OO languages that didn't/don't have
>>inheritance, 
> 
> 
> VB4 - VB6
> 
VB6 has a kind of inheritance via interface/delegation. The interface
part is for subtyping, the delegation part (which has to be done
manually - yuck) is for implementation inheritance. Needless to say it's
a king-size PITA...

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: datetime: the date of the day one month ago...how?

2006-04-12 Thread Max M
gabor wrote:
> hi,
> 
> i'm trying to get the date of the day one month ago.
> 
> for example:
> 
> today = 12.apr.2006
> one-month-ago = 12.mar.2006
> 
> so:
> 
> one-month-ago(12.apr.2006) = 12.mar.2006
> 
> of course sometimes it gets more complicated, like:
> 
> one-month-ago(31.mar.2006)
> 
> or
> 
> one-month-ago(1.jan.2006)
> 
> the datetime.timedelta objects only work with hours or days or weeks, 
> not month (i understand why)...
> 
> but is there a way to calculate this in python?
> 
> i really don't want to calculate it by myself :-))


It is application specific. So how *do* you want 
one-month-ago(31.mar.2006) or one-month-ago(28.feb.2006) to work? No one 
can know but you.


-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science

Phone:  +45 66 11 84 94
Mobile: +45 29 93 42 96
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't connect to SimpleXMLRPCServer. Help needed.

2006-04-12 Thread Jose Carlos Balderas Alberico
Thank you for the quick reply John...
Is there a way to sort this out? Should I specify another address here:
 
server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000), )
 
instead of "localhost" ?
 
I'm kind of new to client/server programming, so I'm at a loss here.
Thank you very much for your attention.
 
Jose Carlos.
 
 
 
2006/4/12, John Abel <[EMAIL PROTECTED]>:
Your server is only listening on 127.0.0.1.Jose Carlos Balderas Alberico wrote:
> Up till now I've been setting up my server and client in the same> machine, using the "localhost" address for everything.> Once I've made it work, I need to move my client application to the
> computer where it'll be run from, and for some reason, I get a> socket.error: (111, 'connection refused').>> The server is listening on port 8000. I've used the line>> server = 
SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000), )> ##register functions...> ...> ...> server.serve_forever()>>> And the client does the following:
>> host = ":8000" (where  is the server's IP address)> conn = xmlrpclib.connect(host)> data = "" (requestData is a function previously> registered in the server)
>> I've made sure the server is listening on port 8000, since the netstat> command says it's listening on port 8000.> I've also pinged the server from the client and viceversa and I get an> answer. So they can see each other.
>> I've tried looking in google but couldn't find a solution to this> problem. Anyone can give me a hand on this?> Thank you very much.>> Jose Carlos.
-- 
http://mail.python.org/mailman/listinfo/python-list

a project to standardize script writing in my environment

2006-04-12 Thread s99999999s2003
hi
in my environment, besides shell scripts written for sys admin tasks,
there are shell scripts that call java programs which in turn will do
various processing like connecting to databases and doing manipulation
of data. My programmers all know only Java and so this is how the java
programs come about. Also, some scripts were written in Perl by some
admins who left, and successors have difficulty grasping perl syntax
and how it works.
My intention is to replace these scripts and java programs to python
scripts, and in future, any processing of text or running queries to
databases will be written in python using relevant modules.  Browsing
the clp  newsgroup on the advantages and comparisons of shell,perl,java
and of course python,  as the language of choice for writing scripts, i
chose python as i think it has many benefits, like readability etc
etc...
Now i am preparing to write a recommendation to my boss for "endorsing"
python as the scripting language of choice. Is it a project worth doing
at least for my environment? What are the things that i should consider
if i were to go ahead?
thanks

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


Re: list.clear() missing?!?

2006-04-12 Thread Duncan Booth
Steven D'Aprano wrote:

> But that is precisely the same for the other timeit tests too.
> 
> for _i in _it:
> x = range(10)
Allocate list.
Allocate ob_item array to hold pointers to 1 objects
Allocate 99900 integer objects
setup list

> del x[:]
Calls list_clear which:
  decrements references to 99900 integer objects, freeing them
  frees the ob_item array

... next time round ...
> x = range(10)

Allocate new list list.
Allocate ob_item array probably picks up same memory block as last time
Allocate 99900 integer objects, probably reusing same memory as last time
setup list

> 
> etc.
> 
> The question remains -- why does it take longer to do X than it takes to
> do X and then Y?

>>> for _i in _it:
...   x = range(10); 

Allocate list.
Allocate ob_item array to hold pointers to 1 objects
Allocate 99900 integer objects
setup list

... next time round ...
Allocate another list
allocate a second ob_item array
allocate another 99900 integer objects
setup the list
then deletes the original list, decrements and releases original integers, 
frees original ob_item array.

Uses twice as much everything except the actual list object. The actual 
work done is the same but I guess there are likely to be more cache misses.
Also there is the question whether the memory allocation does or does not 
manage to reuse the recently freed blocks. With one large block I expect it 
might well end up reusing it, with two large blocks being freed alternately 
it might not manage to reuse either (but that is just a guess and maybe 
system dependant).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UDP max datagram size

2006-04-12 Thread malv
I seem to recall from UDP datagram tests between linux and XP I ran a
few years ago that XP maximum datagram sizes are indeed smaller than
linux.

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


Re: datetime: the date of the day one month ago...how?

2006-04-12 Thread Kent Johnson
gabor wrote:
> hi,
> 
> i'm trying to get the date of the day one month ago.
> 
> for example:
> 
> today =   12.apr.2006
> one-month-ago = 12.mar.2006

dateutil has one implementation of this:
http://labix.org/python-dateutil

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


Re: datetime: the date of the day one month ago...how?

2006-04-12 Thread gabor
Max M wrote:
> gabor wrote:
>> hi,
>>
>> i'm trying to get the date of the day one month ago.
>>
>> for example:
>>
>> today = 12.apr.2006
>> one-month-ago = 12.mar.2006
>>
>> so:
>>
>> one-month-ago(12.apr.2006) = 12.mar.2006
>>
>> of course sometimes it gets more complicated, like:
>>
>> one-month-ago(31.mar.2006)
>>
>> or
>>
>> one-month-ago(1.jan.2006)
>>
>> the datetime.timedelta objects only work with hours or days or weeks, 
>> not month (i understand why)...
>>
>> but is there a way to calculate this in python?
>>
>> i really don't want to calculate it by myself :-))
> 
> 
> It is application specific. So how *do* you want 
> one-month-ago(31.mar.2006) or one-month-ago(28.feb.2006) to work? No one 
> can know but you.
> 
> 

well, give me a solution for ANY behaviour :)

or, let's specify it then:

i want the day that you get by intutively saying "one month ago". means 
usually picking the same day in the previous month. if that day does not 
exist, i want the nearest day that exist and was BEFORE the nonexistent day.

one-month-ago(31.mar.2006) = 28.feb.2006
one-month-ago(28.feb.2006) = 28.jan.2006


so, now that we have a spec, is there a way to achieve this in python 
without writing the algorithm by myself?


thanks,
gabor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't connect to SimpleXMLRPCServer. Help needed.

2006-04-12 Thread Jose Carlos Balderas Alberico
Okay, I changed this:
  server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000), )
for this:
  server = SimpleXMLRPCServer.SimpleXMLRPCServer(('', 8000), )
 
Replacing "localhost" with two simple quotes ' makes it work.
Anyone knows the reason for this?
 
Thank so much.
 
Jose Carlos
 
2006/4/12, Jose Carlos Balderas Alberico <[EMAIL PROTECTED]>:


Thank you for the quick reply John...
Is there a way to sort this out? Should I specify another address here:

 
server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000), )
 

instead of "localhost" ?
 
I'm kind of new to client/server programming, so I'm at a loss here.
Thank you very much for your attention.
 
Jose Carlos.
 
 
 
2006/4/12, John Abel <[EMAIL PROTECTED]>: 

Your server is only listening on 
127.0.0.1.Jose Carlos Balderas Alberico wrote: > Up till now I've been setting up my server and client in the same> machine, using the "localhost" address for everything.> Once I've made it work, I need to move my client application to the 
> computer where it'll be run from, and for some reason, I get a> socket.error: (111, 'connection refused').>> The server is listening on port 8000. I've used the line>> server = 
SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000), )> ##register functions...> ...> ...> server.serve_forever()>>> And the client does the following:
>> host = ":8000" (where  is the server's IP address)> conn = xmlrpclib.connect(host)> data = "" (requestData is a function previously> registered in the server) 
>> I've made sure the server is listening on port 8000, since the netstat> command says it's listening on port 8000.> I've also pinged the server from the client and viceversa and I get an> answer. So they can see each other. 
>> I've tried looking in google but couldn't find a solution to this> problem. Anyone can give me a hand on this?> Thank you very much.>> Jose Carlos.

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

Python2CPP ?

2006-04-12 Thread Michael Yanowitz
Hello:

   One topic that has always interested me are the Language translators.
Are there any that convert between Python and C++ or Python and Java?
I remember seeing one that converts from Python to or from Perl but couldn't
find it on a quick google search. I did find a Python2C
http://sourceforge.net/projects/p2c/ and I found:
http://www.strout.net/python/ai/python2c.py  which are obviously incomplete.
   I know there have been many discussions recently regarding C and C++.
I am (or is it - was?) a C/C++ programmer for over 15 years. Just started
with Python as we need to write come quick code in script form which can
be generated and run through an interpreter.
   If not could there be a converter from Python to/from Language X and
from Language X to/from C or C++?
   In another thread mentioning a decompiler. Perhaps Python to Assembly
and Assembly 2 C?

Thanks in advance:

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


Re: Python2CPP ?

2006-04-12 Thread Szabolcs Berecz
First of all: why do you want to translate pythont to C++?

Anyway, this has a C back-end:
http://www.pypy.org

Szabi

On 4/12/06, Michael Yanowitz <[EMAIL PROTECTED]> wrote:
> Hello:
>
>One topic that has always interested me are the Language translators.
> Are there any that convert between Python and C++ or Python and Java?
> I remember seeing one that converts from Python to or from Perl but couldn't
> find it on a quick google search. I did find a Python2C
> http://sourceforge.net/projects/p2c/ and I found:
> http://www.strout.net/python/ai/python2c.py  which are obviously incomplete.
>I know there have been many discussions recently regarding C and C++.
> I am (or is it - was?) a C/C++ programmer for over 15 years. Just started
> with Python as we need to write come quick code in script form which can
> be generated and run through an interpreter.
>If not could there be a converter from Python to/from Language X and
> from Language X to/from C or C++?
>In another thread mentioning a decompiler. Perhaps Python to Assembly
> and Assembly 2 C?
>
> Thanks in advance:
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie wxPython questions.

2006-04-12 Thread dfh
[EMAIL PROTECTED] wrote:
> I am running through the wxPython guide and docs and extrapolating
> enough to get confused.

There is mailing list for  wxPython users -
[EMAIL PROTECTED] It is pretty active and its
members, including Robin Dunn the main wxPython developer, are always
very helpful.

If you post code there, I suggest you include it as an attachment to
avoid line wrapping in the message body - the one thing Python doesn't
like! 

Regards,
David Hughes

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


Re: Can't connect to SimpleXMLRPCServer. Help needed.

2006-04-12 Thread John Abel
Your server is only listening on 127.0.0.1.

Jose Carlos Balderas Alberico wrote:
> Up till now I've been setting up my server and client in the same 
> machine, using the "localhost" address for everything.
> Once I've made it work, I need to move my client application to the 
> computer where it'll be run from, and for some reason, I get a 
> socket.error: (111, 'connection refused').
>  
> The server is listening on port 8000. I've used the line
>  
> server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000), )
> ##register functions...
> ...
> ...
> server.serve_forever()
>  
>  
> And the client does the following:
>  
> host = ":8000" (where  is the server's IP address)
> conn = xmlrpclib.connect(host)
> data = conn.requestData() (requestData is a function previously 
> registered in the server)
>  
> I've made sure the server is listening on port 8000, since the netstat 
> command says it's listening on port 8000.
> I've also pinged the server from the client and viceversa and I get an 
> answer. So they can see each other.
>  
> I've tried looking in google but couldn't find a solution to this 
> problem. Anyone can give me a hand on this?
> Thank you very much.
>  
> Jose Carlos.

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


RE: Python2CPP ?

2006-04-12 Thread Michael Yanowitz
> First of all: why do you want to translate pythont to C++?
>
> Anyway, this has a C back-end:
> http://www.pypy.org
>
> Szabi

  Thanks. I want to translate from Python to C++ for a few reasons:
1) Curiosity. I would like to see how well the translation goes.
2) Efficiency. It is alot quicker to code something in Python. If I can
   write it in Python and auto-convert it to C++. I would save time coding.
3) Education. I would learn more about Python, C++, their similarities and
differences.
4) Other. Just want to know how well Language translators work these days. I
have seen
   Fortran2C and Pascal2C translators in the past. Would like to see how
well these
   work with Python.

Thanks in advance:

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


Re: Problem with spawning an external process

2006-04-12 Thread Nico Kruger
Not working with Python 2.3.5 here on Fedora Core 2 :(. Oh well, at
least it's working on 2.4. 

Must be specific to something in the combination of Fedora Core 2 and
Python 2.3.x, that is all I can think of.

On Wed, 2006-04-12 at 12:55, Nico Kruger wrote:
> Daniel, you are correct, it is not that good news for me :)
> 
> But anyway, thanks to your responses, I installed Python 2.4.3 and it is
> working on my machine now as well. We were overdue for an upgrade to our
> Python environment anyways, so I think this is the final incentive to
> upgrade.
> 
> Although, I will download 2.3.5 now and get back to you with the status.
> Would be interesting to know when exactly this problem was fixed, maybe
> it would help to know what is causing the problem? It really is a
> strange one.
> 
> Again, thanks for your effort!
> 
> 



--
NetSys International (Pty) Ltd.
Tel : +27 12 349 2056
Fax : +27 12 349 2757
Web : http://www.netsys.co.za
P.O. Box 35798, Menlo Park, 0102, South Africa


The information contained in this communication is confidential and may be
legally privileged. It is solely for use of the individual or entity to whom
is addressed and others authorised to receive it. If you are not the intended
recipient you are hereby notified that any disclosure, copying, distribution
or taking of any action in reliance on the contents of this information is
strictly prohibited and may be unlawful.

This Message has been scanned for viruses and dangerous content by the NetSys
International Mail Scanner and is believed to be clean.

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


Re: symbolic links, aliases, cls clear

2006-04-12 Thread af . dingo
If I may recommend an alternative,

print "\033[H\033[J"

the ansi sequence to clear the screen.

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


Re: Can't connect to SimpleXMLRPCServer. Help needed.

2006-04-12 Thread John Abel
Using the '' makes it listen on all interfaces.

Jose Carlos Balderas Alberico wrote:
> Okay, I changed this:
>   server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000), 
> )
> for this:
>   server = SimpleXMLRPCServer.SimpleXMLRPCServer(('', 8000), )
>  
> Replacing "localhost" with two simple quotes ' makes it work.
> Anyone knows the reason for this?
>  
> Thank so much.
>  
> Jose Carlos
>  
> 2006/4/12, Jose Carlos Balderas Alberico 
> <[EMAIL PROTECTED] >:
>
> Thank you for the quick reply John...
> Is there a way to sort this out? Should I specify another address
> here:
>  
> server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost",
> 8000), )
>  
> instead of "localhost" ?
>  
> I'm kind of new to client/server programming, so I'm at a loss here.
> Thank you very much for your attention.
>  
> Jose Carlos.
>  
>  
>
>
>  
> 2006/4/12, John Abel <[EMAIL PROTECTED] >:
>
> Your server is only listening on 127.0.0.1 .
>
> Jose Carlos Balderas Alberico wrote:
> > Up till now I've been setting up my server and client in the same
> > machine, using the "localhost" address for everything.
> > Once I've made it work, I need to move my client application
> to the
> > computer where it'll be run from, and for some reason, I get a
> > socket.error: (111, 'connection refused').
> >
> > The server is listening on port 8000. I've used the line
> >
> > server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost",
> 8000), )
> > ##register functions...
> > ...
> > ...
> > server.serve_forever()
> >
> >
> > And the client does the following:
> >
> > host = ":8000" (where  is the server's IP address)
> > conn = xmlrpclib.connect(host)
> > data = conn.requestData() (requestData is a function previously
> > registered in the server)
> >
> > I've made sure the server is listening on port 8000, since
> the netstat
> > command says it's listening on port 8000.
> > I've also pinged the server from the client and viceversa and
> I get an
> > answer. So they can see each other.
> >
> > I've tried looking in google but couldn't find a solution to this
> > problem. Anyone can give me a hand on this?
> > Thank you very much.
> >
> > Jose Carlos.
>
>
>  
>
>

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


Re: Python2CPP ?

2006-04-12 Thread Szabolcs Berecz
On 4/12/06, Michael Yanowitz <[EMAIL PROTECTED]> wrote:
> 2) Efficiency. It is alot quicker to code something in Python. If I can
>write it in Python and auto-convert it to C++. I would save time coding.

I don't think you will get a more efficient code. The reason is the
extremely dynamic nature of python. Almost everything is done at
runtime. I think one goal of PyPy is to automatically infer the types
of variable, but I don't think they have reached that point, yet. One
project you can consider is the psycho python package which generates
specialized native code at the price of high memory consumption.

> 3) Education. I would learn more about Python, C++, their similarities and
> differences.

I don't think so. Higher level languages translated to C are not very
readable (or at least that's what I have seen)

> 4) Other. Just want to know how well Language translators work these days. I
> have seen
>Fortran2C and Pascal2C translators in the past. Would like to see how
> well these
>work with Python.

Than I think PyPy is the way to go. I have heard about another project
with the goal of translating python to high efficiency C++ code but
forgot the url. Anybody?

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


RE: Python2CPP ?

2006-04-12 Thread Diez B. Roggisch
> 1) Curiosity. I would like to see how well the translation goes.

If there is something that works, it will look awful to the eye.
Code-generators are generally not very idiomatic - they mapping is to
localized to e.g. factorize out a more complex loop to something a
generator might to much better.

I suggest you take a look at pyrex, a python-like language that bridges
python and C by generating C.

> 2) Efficiency. It is alot quicker to code something in Python. If I can
>write it in Python and auto-convert it to C++. I would save time
>coding.

Then let it run in python.

> 3) Education. I would learn more about Python, C++, their similarities and
> differences.

I also doubt that. digging into generated, non-idiomatic code won't do much
for you to grasp what is behind Python or C++ as well. Think e.g. of
templating, a major feature in C++ that certainly won't be utilized by a
code-generator that does everything based on python C-structures and their
C-API.

Regards,

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


example of logging w/ user-defined keywords?

2006-04-12 Thread Chris Curvey
Several things that I've read lead me to think this is possible, but I
can't figure out how to do it.  I have some information (a "job
number")  that I would like logged on every log message, just like the
time or the severity.

I saw some mail threads that suggested that there was an easy way to do
this, but I havent' found any examples.  Is there a simple way to do
this, or do I need to write my own logger subclass?

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


Re: example of logging w/ user-defined keywords?

2006-04-12 Thread Peter Hansen
Chris Curvey wrote:
> Several things that I've read lead me to think this is possible, but I
> can't figure out how to do it.  I have some information (a "job
> number")  that I would like logged on every log message, just like the
> time or the severity.
> 
> I saw some mail threads that suggested that there was an easy way to do
> this, but I havent' found any examples.  Is there a simple way to do
> this, or do I need to write my own logger subclass?

class MyClass:
 def __init__(self, name, job):
self.logger = logging.getLogger(name)
self.job = job


 def log(self, msg):
self.logger.debug('#%d: %s' % (self.job, msg)


Then just call self.log('foo') whenever you want to log something.

If this isn't sufficient please describe what requirements you have that 
it doesn't meet.  (Subclassing Logger is certainly a simple way to do it 
though... in that case you would just pass the job number to the 
subclass when you construct it and it could do something like that above.

-Peter

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


Re: Python2CPP ?

2006-04-12 Thread Jay Parlar

On Apr 12, 2006, at 5:13 AM, Michael Yanowitz wrote:
>>
>
>   Thanks. I want to translate from Python to C++ for a few reasons:
> 1) Curiosity. I would like to see how well the translation goes.
> 2) Efficiency. It is alot quicker to code something in Python. If I can
>write it in Python and auto-convert it to C++. I would save time 
> coding.
> 3) Education. I would learn more about Python, C++, their similarities 
> and
> differences.
> 4) Other. Just want to know how well Language translators work these 
> days. I
> have seen
>Fortran2C and Pascal2C translators in the past. Would like to see 
> how
> well these
>work with Python.
>
> Thanks in advance:

You want this: http://shed-skin.blogspot.com/  It can only do a subset 
of Python, but it does generate C++ code, and it can see some big 
speedups.

Jay P.

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


Re: symbolic links, aliases, cls clear

2006-04-12 Thread Floyd L. Davidson
[EMAIL PROTECTED] wrote:
>If I may recommend an alternative,
>
>print "\033[H\033[J"
>
>the ansi sequence to clear the screen.

Or so you would hope (however, that is *not* what you have listed!).

Unfortunately, it is poor practice to hard code such sequences.
Instead the proper sequence should be obtained from the
appropriate database (TERMINFO or TERMCAP), and the easy way to
do that is,

   tput clear

-- 
Floyd L. Davidson
Ukpeagvik (Barrow, Alaska) [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular expression intricacies: why do REs skip some matches?

2006-04-12 Thread Chris Lasher
Diez, John, Tim, and Ben, thank you all so much. I now "get it". It
makes logical sense now that the difficulty was actually in the
implementation of findall, which does non-overlapping matches. It also
makes sense, now, that one can get around this by using a lookahead
assertion. Thanks a bunch, guys; this really helped!

Chris

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


Re: Python2CPP ?

2006-04-12 Thread Ben C
On 2006-04-12, Michael Yanowitz <[EMAIL PROTECTED]> wrote:
> Hello:
>
>One topic that has always interested me are the Language translators.
> Are there any that convert between Python and C++ or Python and Java?
> I remember seeing one that converts from Python to or from Perl but couldn't
> find it on a quick google search. I did find a Python2C
> http://sourceforge.net/projects/p2c/ and I found:
> http://www.strout.net/python/ai/python2c.py  which are obviously incomplete.
>I know there have been many discussions recently regarding C and C++.
> I am (or is it - was?) a C/C++ programmer for over 15 years. Just started
> with Python as we need to write come quick code in script form which can
> be generated and run through an interpreter.
>If not could there be a converter from Python to/from Language X and
> from Language X to/from C or C++?

I've heard of an incomplete Python to C++ translator called "Shedskin"

http://pycode.com/modules/?id=40&PHPSESSID=1919541171352770795c2bcee95b46bd

There's also a GNU project afoot for a Python to Scheme translator which
I saw on http://savannah.gnu.org but now cannot find. This would be an
interesting project, I suppose you'd write it in Python, then it could
bootstrap itself into Scheme and C.

Scheme can be translated to C using chicken:

http://www.call-with-current-continuation.org/index.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-12 Thread Floyd L. Davidson
"mp" <[EMAIL PROTECTED]> wrote:
>i have a python program which attempts to call 'cls' but fails:
>
>sh: line 1: cls: command not found

Hm...  (I don't program in Python, so precisely what is
happening isn't something I'm sure about).

But, note how that line starts with "sh:"!  That indicates it is
/bin/sh which is reporting an inability to find a "cls"
command.  It suggests that Python (like most other programming
languages) calls shell scripts using /bin/sh as the default
shell.

The problem is that unix has no command named "cls".

>i tried creating an alias from cls to clear in .profile, .cshrc, and
>/etc/profile, but none of these options seem to work.

In /etc/profile and ~/.profile you will cause an alias to be
defined *for* *interactive* *login* *shells*.  But not for
non-interactive non-login shells, which is what you are invoking
with Python.  The reason is because aliases are not inherited by
sub-shells, and only interactive login shells read those two
files.

Hence your alias is never defined in the subshell your program
executes.

>my conclusion is that a python program that is executing does not use
>the shell (because it does not recognize shell aliases). is this
>correct?

No.

>should i use a symbolic link? if so, where should i place it?

No.

>what is the difference between aliases and symbolic links?

Aliases are a mechanism used by a shell to define a command name
that executes a series of commands.  A symbolic link is a
directory entry that de-references another directory entry, so
that either entry points to the same actual file.

>if i execute a command like 'clear' to clear the screen, where does the
>shell look to find the command 'clear'?

It looks in locations specified by the PATH variable.  By
default that will be a minimal list defined by the login
program, but it might be significantly added to in the
/etc/profile or other shell init scripts.

The question you need to answer first is what happens if your
Python program tries to execute /clear/ rather than /cls/.  If
that works, then your PATH variable is set correctly.  If it
doesn't work, verify that there is in fact a program named
/clear/ that can be run from a shell command line.  Then figure
out how to set an appropriate PATH variable for your Python
program.

Note that if /clear/ does work, but you want this script to use
/cls/ so that it is portable to some silly OS where a /cls/
exists...  You can define a shell function (which will be
inherited by sub-shells) to look like this,

  function cls () {
 clear;
  }

And place it where ever is appropriate (/etc/profile is one place).

>i'm using os x.

I don't know anything about it... :-)

-- 
Floyd L. Davidson
Ukpeagvik (Barrow, Alaska) [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter vs PyGTK

2006-04-12 Thread JyotiC
Thanx for the help.

Does all gui's take time to load.
is there a way to dec this time.

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


random.sample with long int items

2006-04-12 Thread jordi
I need the random.sample functionality where the population grows up to
long int items. Do you know how could I get this same functionality in
another way? thanks in advance.
Jordi

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


Re: random.sample with long int items

2006-04-12 Thread Paul Rubin
"jordi" <[EMAIL PROTECTED]> writes:
> I need the random.sample functionality where the population grows up to
> long int items. Do you know how could I get this same functionality in
> another way? thanks in advance.

Nothing stops you:

>>> from random import sample
>>> a = [n**25 for n in range(6)]
>>> a
[0, 1, 33554432, 847288609443L, 1125899906842624L, 298023223876953125L]
>>> sample(a,2)
[1125899906842624L, 298023223876953125L]
>>> sample(a,2)
[298023223876953125L, 847288609443L]
>>> 

Is this what you were asking, or did you mean something different?
-- 
http://mail.python.org/mailman/listinfo/python-list


REMINDER: BayPIGgies: April 13, 7:30pm (IronPort)

2006-04-12 Thread Aahz
The next meeting of BayPIGgies will be Thurs, April 13 at 7:30pm at
IronPort.

This meeting features JJ reviewing "Professional Software Development"
with discussion and newbie questions afterward.


BayPIGgies meetings alternate between IronPort (San Bruno, California)
and Google (Mountain View, California).  For more information and
directions, see http://baypiggies.net/


Before the meeting, we sometimes meet at 6pm for dinner.  Discussion of
dinner plans is handled on the BayPIGgies mailing list.  

Advance notice:  We have a speaker for May.  We can use speakers for
June/July.  Please e-mail [EMAIL PROTECTED] if you want to suggest an
agenda (or volunteer to give a presentation).
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"LL YR VWL R BLNG T S"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Decorators, Identity functions and execution...

2006-04-12 Thread Dave Hansen
On Wed, 12 Apr 2006 17:19:25 +1200 in comp.lang.python, Lawrence
D'Oliveiro <[EMAIL PROTECTED]> wrote:

>In article <[EMAIL PROTECTED]>,
> "Terry Reedy" <[EMAIL PROTECTED]> wrote:
>
>>"Sybren Stuvel" <[EMAIL PROTECTED]> wrote in
>> > I don't care about how people see my tabs. I use one tab for every
>>> indent level, so no matter how you set your tab width, my code will
>>> look consistent.
>>
>>Unless they view with tab_width = 0, as with some news readers.
>
>I have my newsreader set to use a proportional font, so the point is 
>moot.

Even in a proportional font, spaces all have the same width.  Though
not as wide as a fixed font...

Regards,
-=Dave

-- 
Change is inevitable, progress is not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compleated Begginers Guide. Now What?

2006-04-12 Thread Christos Georgiou
On Tue, 11 Apr 2006 07:37:23 -0400, rumours say that Steve Holden
<[EMAIL PROTECTED]> might have written:

>James Stroud wrote:

>> Mirco Wahab wrote:
 
>>>Jay wrote:

>>>Malchick, you cracked your veshchs to classes, which is
>>>not that gloopy. So rabbit on them and add class methods
>>>that sloosh on beeing called and do the proper veshchs
>>>to the gulliwuts of their classes.
 
>> Brillig!
 
>But neither helpful nor sympathetic.

Neither sympythetic, too (where “sympythetic” is the typical behaviour on
c.l.py)
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list

converting lists to strings to lists

2006-04-12 Thread robin
hi,

i'm doing some udp stuff and receive strings of the form '0.87
0.25 0.79;\n'
what i'd need though is a list of the form [0.87 0.25 0.79]
i got to the [0:-3] part to obtain a string '0.87 0.25
0.79' but i can't find a way to convert this into a list. i tried
eval() but this gives me the following error:

Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 1
.87 0.25 0.79000

and i have the same problem the other way round. e.g. i have a list
which i need to convert to a string in order to send it via udp.
btw: i cannot use pickle, since i'm sending stuff to a LISP programme.

thank you in advance for your help!
best,

robin

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


Re: random.sample with long int items

2006-04-12 Thread Steven D'Aprano
On Wed, 12 Apr 2006 06:29:01 -0700, jordi wrote:

> I need the random.sample functionality where the population grows up to
> long int items. Do you know how could I get this same functionality in
> another way? thanks in advance.

I'm thinking you might need to find another way to do whatever it is you
are trying to do.

If you can't, you could do something like this:

- you want to randomly choose a small number of items at random from a
population of size N, where N is very large.

e.g. you would do this: random.sample(xrange(10**10), 60)
except it raises an exception.

- divide your population of N items in B bins of size M, where both B and
M are in the range of small integers. Ideally, all your bins will be equal
in size.

e.g. 
bins = [xrange(start*10**5, (start+1)*10**5) \
for start in xrange(10**5)]


- then, to take a sample of n items, do something like this:

# bins is the list of B bins;
# each bin has M items, and B*M = N the total population.
result = []
while len(result) < sample_size:
# choose a random bin
bin = random.choice(bins)
# choose a random element of that bin
selection = random.choice(bin)
if selecting_with_replacement:
result.append(selection)
else:
# each choice must be unique
if not selection in result:
result.append(selection)


Hope that helps.


-- 
Steven.

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


Re: random.sample with long int items

2006-04-12 Thread Steven D'Aprano
On Wed, 12 Apr 2006 06:44:29 -0700, Paul Rubin wrote:

> "jordi" <[EMAIL PROTECTED]> writes:
>> I need the random.sample functionality where the population grows up to
>> long int items. Do you know how could I get this same functionality in
>> another way? thanks in advance.
> 
> Nothing stops you:
> 
> >>> from random import sample
> >>> a = [n**25 for n in range(6)]
> >>> a
> [0, 1, 33554432, 847288609443L, 1125899906842624L, 298023223876953125L]
> >>> sample(a,2)
> [1125899906842624L, 298023223876953125L]

No, I think he means the size of the list is big enough to need a long
int. Something like xrange(10**10) or even bigger.

>>> random.sample(xrange(10*10), 10)
[96, 45, 90, 52, 57, 72, 94, 73, 79, 97]
>>> random.sample(xrange(10**10), 10)
Traceback (most recent call last):
  File "", line 1, in ?
OverflowError: long int too large to convert to int


-- 
Steven.

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


Re: converting lists to strings to lists

2006-04-12 Thread Eric Deveaud
robin wrote:
>  hi,
> 
>  i'm doing some udp stuff and receive strings of the form '0.87
>  0.25 0.79;\n'
>  what i'd need though is a list of the form [0.87 0.25 0.79]
>  i got to the [0:-3] part to obtain a string '0.87 0.25
>  0.79' but i can't find a way to convert this into a list. i tried
>  eval() but this gives me the following error:

check pydoc string about split

my_string = '0.87 0.25 0.79;\n'
my_list = my_string.split()
print my_list


>  and i have the same problem the other way round. e.g. i have a list
>  which i need to convert to a string in order to send it via udp.


my_new_string = ' '.join(my_list)
print my_new_string

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


Re: random.sample with long int items

2006-04-12 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> e.g. you would do this: random.sample(xrange(10**10), 60)
> except it raises an exception.

For a population that large and a sample that small (less than
sqrt(population size), the chance of collision is fairly small, so you
can just discard duplicates.

This relies on Python 2.4's randrange function to generate arbitrarily
large ranges, which in turn relies on having getrandbits (new 2.4
feature, thanks Ray) available:

samp = Set()
while len(samp) < 60:
   samp.add(random.randrange(10**10))

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


Re: converting lists to strings to lists

2006-04-12 Thread gry
Read about string split and join.  E.g.:
l = '0.87 0.25 0.79'
floatlist = [float(s) for s in l.split()]

In the other direction:
floatlist = [0.87, 0.25, 0.79004]
outstring = ' '.join(floatlist)

If you need to control the precision(i.e. suppress the 4), read
about
the string formatting operator "%".

-- George Young

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


Re: converting lists to strings to lists

2006-04-12 Thread robin
thanks for your answer. split gives me a list of strings, but i found a
way to do what i want:

input='0.1, 0.2, 0.3;\n'
input = list(eval(input[0:-2]))
print input
> [0.10001, 0.20001, 0.2]

this does fine... but now, how do i convert this list to a string?

my_new_string = ' '.join(input)

gives me:

Traceback (most recent call last):
  File "", line 1, in ?
TypeError: sequence item 0: expected string, float found

thanks,

robin

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


Re: converting lists to strings to lists

2006-04-12 Thread Steven D'Aprano
On Wed, 12 Apr 2006 06:53:23 -0700, robin wrote:

> hi,
> 
> i'm doing some udp stuff and receive strings of the form '0.87
> 0.25 0.79;\n'
> what i'd need though is a list of the form [0.87 0.25 0.79]
> i got to the [0:-3] part to obtain a string '0.87 0.25
> 0.79' but i can't find a way to convert this into a list. i tried
> eval() but this gives me the following error:
> 
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "", line 1
> .87 0.25 0.79000


# untested!
def str2list(s):  
"""Expects a string of the form '0.87 0.25 0.79;\n' and
returns a list like [0.87, 0.25, 0.79]

WARNING: this function has only limited error checking.
"""
s = s.strip()  # ignore leading and trailing whitespace
if s.endswith(';'): 
s = s[:-1]
L = s.split()
assert len(L) == 3, "too many or too few items in list."
return [float(f) for f in L]


> and i have the same problem the other way round. e.g. i have a list
> which i need to convert to a string in order to send it via udp.

That's even easier.

def list2str(L):
"""Expects a list like [0.87, 0.25, 0.79] and returns a string 
of the form '0.87 0.25 0.79;\n'.
"""
return "%.6f %.6f %.6f;\n" % tuple(L)



-- 
Steven.

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


Re: list.clear() missing?!?

2006-04-12 Thread John Salerno
Steven D'Aprano wrote:

> But name.clear() meaning "mutate the object referenced by name to the
> empty state" is a very natural candidate for a method, and I don't
> understand why lists shouldn't have it.

Funny this even comes up, because I was just trying to 'clear' a list 
the other day. But it sounds like it's been an issue for a while. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: random.sample with long int items

2006-04-12 Thread jordi
That is just what I need. I did't mind on 'divide and conquer' :(

Thanks a lot!

--
Jordi

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


Re: Tkinter vs PyGTK

2006-04-12 Thread gregarican
JyotiC wrote:

> Thanx for the help.
>
> Does all gui's take time to load.
> is there a way to dec this time.

Have you tried loading a Java GUI app through launching the Java
Virtual Machine? That's pretty slow too. And that's a bytecode compiled
medium. Unfortunately most interpreted programming languages like Perl,
Ruby, Python, etc. are pretty slow loading initial GUI environments.
That's the performance penalty that is offset by the benefits and
efficiency of coding in a very high level language. Less than a second
of load time doesn't seem to be too much of a detraction in my book,
however. If you want pure speed you would need to code in a true
compiled programming language such as C (e.g. - GTK GUI toolkit), C++
(e.g. - Qt GUI toolkit), etc. But what fun is that :-)

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


Re: redirecting web page

2006-04-12 Thread Thomas Guettler
Am Tue, 11 Apr 2006 10:38:13 -0700 schrieb dai:

> Hi, I am a newbie about python. Now I am modifying the tinyHTTPProxy to
> redirect a client's request to our company's webpage.
> I don't know how can I do this. What I want to do now is to modify the
> headers, but i still didn't figure out how to do it.
> Thank you very much

Some days ago there was a similar question. It might help you:

http://groups.google.com/group/comp.lang.python/browse_frm/thread/7d325df38293fe18/7b29f0d9f11474ba?lnk=st&q=guettler+redirect+python&rnum=1&hl=en#7b29f0d9f11474ba


-- 
Thomas Güttler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher: [EMAIL PROTECTED]

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


Re: converting lists to strings to lists

2006-04-12 Thread Peter Hansen
robin wrote:
> i'm doing some udp stuff and receive strings of the form '0.87
> 0.25 0.79;\n'
> what i'd need though is a list of the form [0.87 0.25 0.79]
> i got to the [0:-3] part to obtain a string '0.87 0.25

Actually, that's already a bug.  You want [0:-2] if you're going to do 
it that way.  Unless you meant that your string actually has a backslash 
and an "n" character, which is doubtful...

You should probably use something more like Steven's solution, although 
I'd personally use s.strip(';') or at least s.rstrip(';') if I had 
semicolons to remove, rather than a combined endswith(';') and slicing 
the last character off.

> 0.79' but i can't find a way to convert this into a list. i tried
> eval() but this gives me the following error:
> 
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "", line 1
> .87 0.25 0.79000

(If you'd posted the full error (that's an incomplete traceback), 
someone would probably have pointed out how to interpret what Python 
told you so that you'd already have figured out what was wrong with that...)

-Peter

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


Re: UDP max datagram size

2006-04-12 Thread Grant Edwards
On 2006-04-12, Iain King <[EMAIL PROTECTED]> wrote:

> Hi.  I've been looking everywhere for this and can't find it, apologies
> if I'm being obtuse:  How do I set the max datagram packet size?

What do you mean "datgram packet size"?

> I'm using the socket module.  It seem like it's hardcoded at
> 255, but I need it to be larger.

My tests show that Linux handles UDP datagrams of up to about
59000 on the "lo" interface and 12500 on Ethernet interfaces.

-- 
Grant Edwards   grante Yow!  Vote for ME
  at   -- I'm well-tapered,
   visi.comhalf-cocked, ill-conceived
   and TAX-DEFERRED!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: converting lists to strings to lists

2006-04-12 Thread robin
yo!

thank you everone! here's how i finally did it:
converting the string into a list:

input = net.receiveUDPData()
input = list(eval(input[0:-2]))

converting the list into a string:

sendout = "%.6f %.6f %.6f;\n" % tuple(winningvector)

maybe i'll even find a way to generalize the list2string bit, so it
accepts arbitrary sized lists...
thanks,

robin

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


just one more question about the python challenge

2006-04-12 Thread John Salerno
Sorry to post here about this again, but the hint forums are dead, and 
the hints that are already there are absolutely no help (mostly it's 
just people saying they are stuck, then responding to themselves saying 
the figured it out! not to mention that most of the hints require 
getting past a certain point in the puzzle before they make sense, and 
i'm just clueless).

Anyway, I'm on level 12 and I not only don't know what to do, but I just 
don't care at this point to work with images anymore. I'd still like to 
read a description of what to do, if one exists somewhere (can't find 
one at all, though), but at this point I'd be happy with the next URL so 
I can just move on. I've been stagnating for a few days and I need to 
use Python again! :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: converting lists to strings to lists

2006-04-12 Thread bruno at modulix
robin wrote:
> thanks for your answer. split gives me a list of strings, 

Of course, why should it be otherwise ?-)

More seriously : Python doesn't do much automagical conversions. Once
you've got your list of strings, you have to convert'em to floats.

> but i found a
> way to do what i want:
> 
> input='0.1, 0.2, 0.3;\n'
> input = list(eval(input[0:-2]))

- eval() is potentially harmful. Using it on untrusted inputs is a bad
idea. In fact, using eval() (or exec) is a bad idea in most cases.

- removing trailing or leading chars is best done with str.strip()

Also, your code is not as readable as the canonical solution (split() +
float)

> print input
> 
>>[0.10001, 0.20001, 0.2]

input = map(float, input.strip('\n;').split(","))
[0.10001, 0.20001, 0.2]

> 
> this does fine... but now, how do i convert this list to a string?
> 
> my_new_string = ' '.join(input)
> 
> gives me:
> 
> Traceback (most recent call last):
>   File "", line 1, in ?
> TypeError: sequence item 0: expected string, float found

Same as above - you need to do the conversion:
' '.join(map(str, input))


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode, command-line and idle

2006-04-12 Thread Egon Frerich
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

What do you have in the IDLE options - General - Default source encoding?

Egon

Kent Johnson schrieb am 12.04.2006 12:40:

> [EMAIL PROTECTED] wrote:
>> Hello again, I've investigated a little bit and this is what I found:
>>
>> If I run IDLE and type
>>
> import sys
> sys.stdin.encoding
>> I get
>>
>> 'cp1252'
>>
>> But if I have a whatever.py file (it can even be a blank file), I edit
>> it with IDLE, I press F5 (Run Module) and then type:
>>
> import sys
> sys.stdin.encoding
>> I get
>>
>> Traceback (most recent call last):
>>   File "", line 1, in ?
>> sys.stdin.encoding
>> AttributeError: PyShell instance has no attribute 'encoding'
>>
>> So when I have the following code in a file:
>>
>> # -*- coding: cp1252 -*-
>> import sys
>> text1 = u'españa'
>> text2 = unicode(raw_input(), sys.stdin.encoding)
>> if text1 == text2:
>> print 'same'
>> else:
>> print 'not same'
>>
>> and I press F5 (Run Module) I get:
>>
>> Traceback (most recent call last):
>>   File "C:\test.py", line 4, in ?
>> text2 = unicode(raw_input(), sys.stdin.encoding)
>> AttributeError: PyShell instance has no attribute 'encoding'
>>
>> This same code works if I just double-click it (run it in the windows
>> console) instead of using IDLE.
>>
>> I'm using Python 2.4.3 and IDLE 1.1.3.
> 
> FWIW all of the above give me 'cp1252', not AttributeError, and the type 
> of sys.stdin on my system is idlelib.rpc.RPCProxy, not PyShell.
> 
> Python 2.4.3 and IDLE 1.1.3 on Win2k
> 
> Kent

- --
Egon Frerich, Freudenbergstr. 16, 28213 Bremen

E-Mail: [EMAIL PROTECTED]
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.2.2 (MingW32)
Comment: GnuPT 2.7.2
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEPOpuuTzybIiyjvURAqKTAJ9omGK03L9p5dHpzjqN9Kz1w6cTYACghO6r
VG30LibkskG9M2boF/lTc0s=
=Xl96
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: converting lists to strings to lists

2006-04-12 Thread bruno at modulix
robin wrote:
> yo!
> 
> thank you everone! here's how i finally did it:
> converting the string into a list:
> 
>   input = net.receiveUDPData()
>   input = list(eval(input[0:-2]))

You'll run into trouble with this.

> converting the list into a string:
> 
>   sendout = "%.6f %.6f %.6f;\n" % tuple(winningvector)
> 
> maybe i'll even find a way to generalize the list2string bit, so it
> accepts arbitrary sized lists...

sendout = "%s;\n" % " ".join(["%.6f" % float(s) for s in winningvector])



-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list.clear() missing?!?

2006-04-12 Thread Steven Bethard
Steven D'Aprano wrote:
> On Tue, 11 Apr 2006 14:49:04 -0700, Ville Vainio wrote:
> 
>> John Salerno wrote:
>>
>>> Thanks guys, your explanations are really helpful. I think what had me
>>> confused at first was my understanding of what L[:] does on either side
>>> of the assignment operator. On the left, it just chooses those elements
>>> and edits them in place; on the right, it makes a copy of that list,
>>> right? (Which I guess is still more or less *doing* the same thing, just
>>> for different purposes)
>> Interestingly, if it was just a "clear" method nobody would be confused.
> 
> Even more importantly, you could say help(list.clear) and learn something
> useful, instead of trying help(del) and getting a syntax error.
[snip more reasons to add list.clear()]

I think these are all good reasons for adding a clear method, but being 
that it has been so hotly contended in the past, I don't think it will 
get added without a PEP.  Anyone out there willing to take out the best 
examples from this thread and turn it into a PEP?

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


Re: just one more question about the python challenge

2006-04-12 Thread Georg Brandl
John Salerno wrote:
> Sorry to post here about this again, but the hint forums are dead, and 
> the hints that are already there are absolutely no help (mostly it's 
> just people saying they are stuck, then responding to themselves saying 
> the figured it out! not to mention that most of the hints require 
> getting past a certain point in the puzzle before they make sense, and 
> i'm just clueless).
> 
> Anyway, I'm on level 12 and I not only don't know what to do, but I just 
> don't care at this point to work with images anymore. I'd still like to 
> read a description of what to do, if one exists somewhere (can't find 
> one at all, though), but at this point I'd be happy with the next URL so 
> I can just move on. I've been stagnating for a few days and I need to 
> use Python again! :)

Have you found the file? You'll have to distribute that file bytewise
in 5 "piles".

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


Re: converting lists to strings to lists

2006-04-12 Thread Eric Deveaud
robin wrote:
>  yo!
> 
>  thank you everone! here's how i finally did it:
>  converting the string into a list:
> 
>   input = net.receiveUDPData()
>   input = list(eval(input[0:-2]))

no pun intented but as you did not know how to use split and join, 
please please DON'T USE eval

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


Re: just one more question about the python challenge

2006-04-12 Thread John Salerno
Georg Brandl wrote:

> Have you found the file? You'll have to distribute that file bytewise
> in 5 "piles".

No, I haven't figured out anything for this puzzle. It seems I might 
have to change the filename of the image to something else, but I don't 
know what. But even after I find the image, I won't know what to do from 
there. I don't know what it means to distribute a file bytewise, but if 
I knew exactly which modules/functions to use, I'd be more than happy 
reading up on them myself. I just hate not knowing where to go to begin 
with (even though I know I probably won't know enough about images to 
use the right module properly either, but I can try).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list.clear() missing?!?

2006-04-12 Thread John Salerno
Steven Bethard wrote:

> I think these are all good reasons for adding a clear method, but being 
> that it has been so hotly contended in the past, I don't think it will 
> get added without a PEP.  Anyone out there willing to take out the best 
> examples from this thread and turn it into a PEP?

What are the usual arguments against adding it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-12 Thread Michael Paoli
Floyd L. Davidson wrote:
> [EMAIL PROTECTED] wrote:
> >If I may recommend an alternative,
> >print "\033[H\033[J"
> Unfortunately, it is poor practice to hard code such sequences.
> Instead the proper sequence should be obtained from the
> appropriate database (TERMINFO or TERMCAP), and the easy way to
> do that is,
>tput clear

Or clear(1), as also mentioned earlier.  Yes, definitely don't want to
hardcode the sequence.  Definitely do use the appropriate terminal
capabilities database (terminfo or termcap) in the appropriate manner
(e.g. clear(1) or tput clear will handle that in the simple case of
shell accessible means to clear the screen).

Most UNIX(/LINUX/BSD/...) implementations support a large number of
terminal types.  E.g. on my system, I check and find that there are
1470 unique terminal types (descriptions) supported - and that's not
including multiple aliases for the same terminal type/description (but
it does count distinct names/files which have differing
configurations, even if they are for the same terminal - such as
changing certain options or behavior of a terminal, or using the
terminal in distinct modes).  Among those terminal types on my system,
I find 154 distinct means of clearing the screen.  Just for
illustrative purposes, here are the top 10 I find, with count of how
many distinct types (descriptions) use that particular sequence:
236 clear=\E[H\E[J,
120 clear=^L,
120 clear=\E[H\E[2J,
 64 clear=\EH\EJ,
 61 clear=\E[2J,
 42 clear=\E[H\E[J$<156>,
 38 clear=^Z,
 36 clear=\E[H\E[J$<50>,
 31 clear=\E[H\E[J$<40>,
 29 clear=\E[2J\E[H,
And of course, sending the wrong sequence (e.g. like trying some to
see what works) can be highly problematic - it can do very nasty
things to some terminals.  E.g. I own one terminal, which among
sequences it supports, is one which effectively says interpret the
following hexadecimal character pairs as bytes, load them into RAM,
and execute them - a relatively sure-fire way to crash the terminal if
it is sent garbage (I used to run into that and other problems with
some BBS systems that would presume everyone must be running something
ANSI capable or that it was safe to do other tests such as see if
certain sequences would render a blue square on one's screen).

references:
"system" call/function, in various programming languages
clear(1)
tput(1)
terminfo(5)
termcap(5)
news:[EMAIL PROTECTED]
news:[EMAIL PROTECTED]

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


Re: just one more question about the python challenge

2006-04-12 Thread Georg Brandl
John Salerno wrote:
> Georg Brandl wrote:
> 
>> Have you found the file? You'll have to distribute that file bytewise
>> in 5 "piles".
> 
> No, I haven't figured out anything for this puzzle. It seems I might 
> have to change the filename of the image to something else, but I don't 
> know what. But even after I find the image, I won't know what to do from 
> there. I don't know what it means to distribute a file bytewise, but if 
> I knew exactly which modules/functions to use, I'd be more than happy 
> reading up on them myself. I just hate not knowing where to go to begin 
> with (even though I know I probably won't know enough about images to 
> use the right module properly either, but I can try).

If you give me the URL of that level, maybe I'll recall what to do.

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


ftp connection and commands (directroy size, etc)

2006-04-12 Thread Arne
Hello everybody!

I am working on Windows XP and I want to do the following:

1. Connecting to a server using ftp
2. Getting the directory structure and the size of each directory in the 
root
3. Getting the owner of a file

All these steps I want to do with python. What I already have is:

1. Connecting to ftp

import ftplib
ftp = ftplib.FTP('host')
ftp.login(')
directory = '/'
ftp.cwd(directory)
linelist = []
ftp.retrlines('LIST', linelist.append)
ftp.close()

2. Getting the directory structure and the size of each directory in the 
root

But I am don't know how to send commands to ftp and capturing the result
If have tried:
a = []
a=ftp.sendcmd('Dir')
By trying to get the directory with 'dir',  I am getting an Error 500 
result.

Furthermore I don't know how to get the directory size. Even I don't know 
the best command for it.

3. Getting the owner of a file

Can I get the owner for one file?  I know with the LIST you get them all.

Please be so kind and post a little bit of a solution code

Thank you very much!
Arne


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


Re: just one more question about the python challenge

2006-04-12 Thread Just
In article <[EMAIL PROTECTED]>,
 John Salerno <[EMAIL PROTECTED]> wrote:

> Georg Brandl wrote:
> 
> > Have you found the file? You'll have to distribute that file bytewise
> > in 5 "piles".
> 
> No, I haven't figured out anything for this puzzle. It seems I might 
> have to change the filename of the image to something else, but I don't 
> know what. But even after I find the image, I won't know what to do from 
> there. I don't know what it means to distribute a file bytewise, but if 
> I knew exactly which modules/functions to use, I'd be more than happy 
> reading up on them myself. I just hate not knowing where to go to begin 
> with (even though I know I probably won't know enough about images to 
> use the right module properly either, but I can try).

Have a look at the url of the image, then try the next.

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


Re: ftp connection and commands (directroy size, etc)

2006-04-12 Thread maxou
Hello Arne

> 1. Connecting to ftp is OK

> 2. Getting the directory structure and the size of each directory in the
> root

-If you want to get the structure of your directory you can simply do
this:

print ftp.dir(path_of_your_directory)
or by creating a list do this
a=ftp.dir(path_of_your_directory)
print a

- To get the size do this:

import os.path
size_directory=os.path.getsize(name_of_directory)
or 
size_file=os.path.getsize(name_of_file)


Max

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


Re: just one more question about the python challenge

2006-04-12 Thread John Salerno
Georg Brandl wrote:
> John Salerno wrote:
>> Georg Brandl wrote:
>>
>>> Have you found the file? You'll have to distribute that file bytewise
>>> in 5 "piles".
>> No, I haven't figured out anything for this puzzle. It seems I might 
>> have to change the filename of the image to something else, but I don't 
>> know what. But even after I find the image, I won't know what to do from 
>> there. I don't know what it means to distribute a file bytewise, but if 
>> I knew exactly which modules/functions to use, I'd be more than happy 
>> reading up on them myself. I just hate not knowing where to go to begin 
>> with (even though I know I probably won't know enough about images to 
>> use the right module properly either, but I can try).
> 
> If you give me the URL of that level, maybe I'll recall what to do.
> 
> Georg

http://www.pythonchallenge.com/pc/return/evil.html

If you're prompted, the name and password are 'huge' and 'file'.

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


  1   2   3   >