Magnus Lycka | 1 Nov 2002 01:01
Picon

Re: compute class name

At 23:26 2002-10-31 +0100, Ulrich Wisser wrote:
>I would like to create new object instances, but compute the
>class name. Simple example
>
>name = "ExampleClass"
>obj = name()

 >>> class X:
...     def __init__(self):
...             print "An X created"
...
 >>> name = 'X'
 >>> a = eval(name+'()')
An X created
 >>> a
<__main__.X instance at 0x00FA6908>

I'm not entirely sure this is the best way to solve
whatever problem you have though... Also note that:

 >>> class Odd:
...     pass
...
 >>> class Even:
...     pass
...
 >>> x = 3
 >>> if x % 2:
...     klass = Odd
... else:
(Continue reading)

Kyle Babich | 1 Nov 2002 02:04

pausing time and perform on exit

I actually have two questions--first do date I have never figured out how to
pause time.  The best of come up with is simple while loops that look for
something to happen but its fair to say I'm clueless.

timetosleep = 0
while timetosleep < 60:
    time.sleep(1)
    timetosleep += 1

Any ideas how to pause time?

Also how would I tell the program to do something when the program is exited
by having the window closed to the computer shut down (anything with the
user manually typing 'quit' into the program)?  I don't even know where to
begin with this.

Thank you agian,
Kyle Babich

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Emile van Sebille | 1 Nov 2002 02:18

Re: compute class name

Ulrich Wisser:
> I would like to create new object instances, but compute the
> class name. Simple example
> 

#----test1.py----
class Test:
    pass

if __name__ == '__main__':
    name = 'Test'
    t = globals()[name]()
    print t

    # now import this module
    import test1
    t1 = test1.__dict__[name]()
    print t1
#---end---

Another thing you could try is directly using a dict:

class OptA:pass
class OptB:pass
class OptC:pass
class OptD:pass

opts = {'OptA':OptA, 'OptB':OptB, 'OptC':OptC, 'OptD':OptD,}

import random
(Continue reading)

Emile van Sebille | 1 Nov 2002 02:35

Re: pausing time and perform on exit

Kyle Babich:
> I actually have two questions--first do date I have never figured out
how to
> pause time.  The best of come up with is simple while loops that look
for
> something to happen but its fair to say I'm clueless.
>
> timetosleep = 0
> while timetosleep < 60:
>     time.sleep(1)

easier to do time.sleep(60)  ;-)  From the docstring:

>>> print time.sleep.__doc__
sleep(seconds)

Delay execution for a given number of seconds.  The argument may be
a floating point number for subsecond precision.
>>>

> Also how would I tell the program to do something when the program is
exited
> by having the window closed to the computer shut down (anything with
the
> user manually typing 'quit' into the program)?  I don't even know
where to
> begin with this.
>

Marc Andre Lemburg speaks to this here:
(Continue reading)

Magnus Lycka | 1 Nov 2002 02:50
Picon

Re: pausing time and perform on exit

At 20:04 2002-10-31 -0500, Kyle Babich wrote:
>I actually have two questions--first do date I have never figured out how to
>pause time.

You can do this at will. As soon as you want to pause
time, it actually does that. But since this will also
pause your mental processes together with everything
else, neither you nor anyone else will ever notice! It's
just you who can do this Kyle, and noone ever notices...
What does this have to do with Python? ;)

>The best of come up with is simple while loops that look for
>something to happen but its fair to say I'm clueless.
>
>timetosleep = 0
>while timetosleep < 60:
>     time.sleep(1)
>     timetosleep += 1

Why is this better than "time.sleep(60)" ?

Can you explain a little more what you are trying to achieve?

>Also how would I tell the program to do something when the program is exited
>by having the window closed to the computer shut down (anything with the
>user manually typing 'quit' into the program)?  I don't even know where to
>begin with this.

If you write a GUI program, there will be special
close events that you can bind to a function. I'm
(Continue reading)

John Abbe | 1 Nov 2002 04:53

Visiting a URL

I've got a newbie question -- i'm looking at altering PikiePikie to 
notify weblogs.com when my weblog updates. I could get all involved 
in XML-RPC, but it's doable through a plain URL. How do i visit a URL 
in Python?

Thanks! Life,
John
--

-- 
   ------===>>  AbbeNormal  <<===------  |            ..:::..
    A wiki-weblog, somewhere under the   |         .:::::::*:::.
      multi-dimensional normal curve     |      ..:::::::::::::::..
       http://ourpla.net/cgi/pikie       |....::::::::::*:::::::::::*....

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Danny Yoo | 1 Nov 2002 09:17
Picon

Re: How to use Numeric / where's the documentation?


[forwarding back to tutor]

On Thu, 31 Oct 2002, Alex Gillis wrote:

> > Yes, thankyou very much, hopefully one day I'll be able to answer
> > other people's questions and repay the tutor list.

No problem!

If you see a question that you'd like to comment on or answer, just charge
ahead; there's no certification required.  *grin*


> Where do you find out info like this, I can look in the libraries to
> find what functions are available and a short description of what they
> do.

The "Numeric" module is an outside extension of Python, so its
documentation isn't known by IDLE, nor by the standard library
documentation at:

    http://python.org/doc/lib

However, there's good news: the Numeric Python page itself has a pretty
good tutorial that you can browse through.  Here it is:

    http://www.pfdubois.com/numpy/html2/numpy.html

There's also some built in help() that we can use in a snap; it's a little
(Continue reading)

Danny Yoo | 1 Nov 2002 09:29
Picon

Re: Visiting a URL


On Thu, 31 Oct 2002, John Abbe wrote:

> I've got a newbie question -- i'm looking at altering PikiePikie to
> notify weblogs.com when my weblog updates. I could get all involved in
> XML-RPC, but it's doable through a plain URL. How do i visit a URL in
> Python?

Hi John,

Do you mean retrieving the contents of the URL resource?  If so, there's a
nice module called 'urllib' that allows us to open URLs as if they were
files.

    http://python.org/doc/lib/module-urllib.html

There's an example near the bottom that you can try out, and if you have
problems, please feel free to contact the Tutor list again.

There's also a nice set of modules to take the "signature" of a string in
an efficient way, so that, rather than having to save an exact snapshot of
a page, you can just store a shorter signature, and do signature
comparison to see if changes have occurred.  Here's a link to one of these
signature digest modules:

    http://python.org/doc/lib/module-hmac.html

Hmmm... on second thought, using that hmac module might be overkill, but
it's still useful to know that it exists.  *grin*

(Continue reading)

Magnus Lycka | 1 Nov 2002 11:54
Picon

Re: Re: compute class name

At 17:18 2002-10-31 -0800, Emile van Sebille wrote:
>Ulrich Wisser:
> > I would like to create new object instances, but compute the
> > class name. Simple example
>    t = globals()[name]()

This is certainly safer than to use eval() that
I mentioned, at least if the string can be changed
outside the control of the programmer.

It's still not perfect though. Someone who could
change the string could still be able to execute
unexpected things defined in the global namespace.

The best option might be to register the classes
that are to be dynamically invoked in a dict, and
to invoke them from that dict.

 >>> classDict = {}
 >>> class A:
...     pass
...
 >>> class B:
...     pass
...
 >>> for klass in [A, B]:
...     classDict[klass.__name__] = klass
...
 >>> print classDict['A']()
<__main__.A instance at 0x0165FE10>
(Continue reading)

fuad python | 1 Nov 2002 12:15
Picon
Favicon

make python easy to use

dear python-ers,

i am a beginner even in python and in programming language. i had used python just for two weeks but i feel it is easier to learn than others. i am looking for any visual python in order to be able to use python more and more easier. anyone can help me please.....!!!

__a beginner python__


Get a bigger mailbox -- choose a size that fits your needs.

Gmane