Python Source

2006-10-21 Thread ArdPy
I am not sure whether this group is the best place to post my thought.
I will ask neverthless:

Is it possible to hack through the code written by Guido van Rossum
that makes the python interpreter. If yes please let me know how to
begin. If its not then pardon me.

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


Where is __builtin__

2006-10-28 Thread ArdPy
Most of the other modules have an accompanying python source file. But
that is not the case with __builtin__. What might be the reason? Isn't
__builtin__ written in python?

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


Re: Very simple request about argument setting.

2006-10-29 Thread ArdPy

[EMAIL PROTECTED] wrote:
> I have the argument items in my class room.
>
> class room:
>   def __init__(self, name, description, items*):
>
> I thought I remembered from a tutorial I read once, and I've read so
> many I feel like an expert of them, that putting a little star* above
> an item makes it accept the argument as a list. But when I tried this,
> I got an invalid syntax error message.
>
There is an error in the syntax the star must prefix the variable name
not suffix it.
Then the items variable will accept the parameter value as a tuple.
> So:
> Question 1: How can I create an argument that accepts a list of
> variable?
It is not clear whether you want to accept a list variable or an
arbitrary number of values as parameter
to the function. So I will explain each case.
def ex(name,*items):
Here name, description and items can all accept lists as arguments.
Additionally items can accept arbitrary
number of arguments even of different types.
Ex:
ex([10,12],12,13.3,'Python')
>
> Question 2: How do I signify to accept each item as one list? (my bet's
> on using another set of parens)
I have answered this already.
>
> Question 3: Or am I going about this all wrong and should always create
> a list before the fuction call and use the list in the function call?
No need u can pass a list directly into the call.

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


I want to work on Python

2006-10-29 Thread ArdPy
Hi there, these days I am desperately searching everywhere on the
Internet for part time python jobs. The reason is I want to get
actively involved with python programming and get some practical
exposure. Please help me in whatever way you can.

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


Re: Very simple request about argument setting.

2006-10-29 Thread ArdPy

[EMAIL PROTECTED] wrote:
> ArdPy wrote:
> > There is an error in the syntax the star must prefix the variable name
> > not suffix it.
> > Then the items variable will accept the parameter value as a tuple.
>
> Hmm, tuples are immutable, right? I need something mutable so that when
> the player picks up an item, it's no longer in the room.
>
> Besides which, I've been playing with this whole thing in the
> interactive interpreter:
>
> >>> def shuf(x,*foo, **bar):
> ...   return x, foo
> ...
> >>> x,foo,bar = shuf(1,2,3,4,5,6,7,8)
> Traceback (most recent call last):
>   File "", line 1, in 
> ValueError: need more than 2 values to unpack
>
> I remember that two stars is for the second tuple, but how do I
> distinguish between what var is for which tuple? I've tried using
> brackets, braces, prenthisies, nothing seems to work. So what I am
> doing wrong?
The thing is that the parameter 'bar' is actually a dictionary object
so the right way of calling shuf is then
x,foo,bar = shuf(1,2,3,4,5,a=6,b=7,c=8)

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


Re: python, threading and a radio timer

2006-10-31 Thread ArdPy

Renato wrote:
> Dear all,
>
> I found this nifty article on how to record your favourite radio show
> using cron and mplayer:
> http://grimthing.com/archives/2004/05/20/recording-streaming-audio-with-mplayer/
>
> Because I couldn't get the date in the filename (and was too lazy to
> look into sh/bash manuals), I decided to use Python. It was a good
> choice, because I decided to improve the timer - learning some more
> Python along the way!
>
> So, the idea is:
> - cron runs the script at a specific time
> - the script starts mplayer, and will keep checking the clock until
> it's time to kill mplayer
> - after mplayer has exited, oggenc is started to turn the raw WAV into
> ogg
> - and finally the remaining WAV is deleted
>
> This basic setting is quite easy, and I used os.spawnvp(os.P_WAIT,...),
> along with another CRON entry to kill mplayer.
>
> But then I got more ambitious: I wanted the script to keep checking if
> mplayer was alive - in case the connection goes down. Moreover, I would
> rather have the script stop mplayer than cron.
>
> At this point, I thought I should get some professional help... :) What
> is the right way to go? Would threads be overkill? If so, where can I
> go about looking for process control/management without delving into
> complex daemon architectures?
>
> So, rather than asking for code, I'm looking for guidance - this is a
> didactic experience!
>
> Cheers,
>
> Renato

I would suggest you take a look at Python 'commands' module. The module
lets you run Unix commands by taking them as parameters to function
calls. That is all I can say with my level of expertise.

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


Re: other ways to check for ?

2006-11-02 Thread ArdPy

elderic wrote:
> Hi there,
>
> are there other ways than the ones below to check for 
> in a python script?
> (partly inspired by wrapping Tkinter :P)
>
> def f():
>print "This is f(). Godspeed!"
>
> 1.: --> sort of clumsy and discouraged by the docs as far as I read
> import types
> type(f) is types.FunctionType
>
> 2.: --> I don't like this one at all
> def null(): pass
> type(f) is type(null)
>
> Basically I'm searching for something like:
> "type(f) is func" like in: "type(x) is int"
>
> Any ideas? =)

you could use assert. Like the one below

assert inspect.isfunction(function_name)

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


Re: small python cgi webserver

2006-11-04 Thread ArdPy

Fabian Braennstroem wrote:
> Hi,
>
> I am looking for a small python script, which starts a small
> web server with python cgi support on a linux machine.
>
> I tried:
>
>
>   #!/usr/bin/env python
>   import sys
>   from CGIHTTPServer import CGIHTTPRequestHandler
>   import BaseHTTPServer
>
>   class MyRequestHandler(CGIHTTPRequestHandler):
>   # In diesem Verzeichnis sollten die CGI-Programme stehen:
>   cgi_directories=["/home/fab/Desktop/cgi-bin"]
>
>
>   def run():
>   # 8000=Port-Nummer
>   #   --> http://localhost:8000/
>   # Fuer http://localhost/
>   #   Port-Nummer auf 80 setzen
>   httpd=BaseHTTPServer.HTTPServer(('', 8000), MyRequestHandler)
>   httpd.serve_forever()
>
>   if __name__=="__main__":
>   print "Starting Server"
>   run()
>
> but when I want to test a small python cgi test file:
>
>
>   #!/usr/bin/python
>   # -*- coding: UTF-8 -*-
>
>   # Debugging für CGI-Skripte 'einschalten'
>   import cgitb; cgitb.enable()
>
>   print "Content-Type: text/html;charset=utf-8\n"
>   print "Hello World!"
>
> I just get the text and not the html output. The file's mode
> is 755.
>
> Is there anything wrong with the webserver script or do I do
> something completely wrong? Maybe, you have a different
> webserver script?
>
> Greetings!
>  Fabian

Probably the server is not executing your CGI script. If it is the
Apache web server that you are using then just ensure the following
settings in your /etc/httpd/conf/httpd.conf file is exactly like
following:


AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all


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


Re: small python cgi webserver

2006-11-04 Thread ArdPy

Fabian Braennstroem wrote:
> Hi,
>
> * ArdPy <[EMAIL PROTECTED]> wrote:
> >
> > Fabian Braennstroem wrote:
> >> Hi,
> >>
> >> I am looking for a small python script, which starts a small
> >> web server with python cgi support on a linux machine.
> >>
> >> I tried:
> >>
> >>
> >>   #!/usr/bin/env python
> >>   import sys
> >>   from CGIHTTPServer import CGIHTTPRequestHandler
> >>   import BaseHTTPServer
> >>
> >>   class MyRequestHandler(CGIHTTPRequestHandler):
> >>   # In diesem Verzeichnis sollten die CGI-Programme stehen:
> >>   cgi_directories=["/home/fab/Desktop/cgi-bin"]
> >>
> >>
> >>   def run():
> >>   # 8000=Port-Nummer
> >>   #   --> http://localhost:8000/
> >>   # Fuer http://localhost/
> >>   #   Port-Nummer auf 80 setzen
> >>   httpd=BaseHTTPServer.HTTPServer(('', 8000), MyRequestHandler)
> >>   httpd.serve_forever()
> >>
> >>   if __name__=="__main__":
> >>   print "Starting Server"
> >>   run()
> >>
> >> but when I want to test a small python cgi test file:
> >>
> >>
> >>   #!/usr/bin/python
> >>   # -*- coding: UTF-8 -*-
> >>
> >>   # Debugging für CGI-Skripte 'einschalten'
> >>   import cgitb; cgitb.enable()
> >>
> >>   print "Content-Type: text/html;charset=utf-8\n"
> >>   print "Hello World!"
> >>
> >> I just get the text and not the html output. The file's mode
> >> is 755.
> >>
> >> Is there anything wrong with the webserver script or do I do
> >> something completely wrong? Maybe, you have a different
> >> webserver script?
> >>
> >> Greetings!
> >>  Fabian
> >
> > Probably the server is not executing your CGI script. If it is the
> > Apache web server that you are using then just ensure the following
> > settings in your /etc/httpd/conf/httpd.conf file is exactly like
> > following:
> >
> > 
> > AllowOverride None
> > Options ExecCGI
> > Order allow,deny
> > Allow from all
> > 
>
> Maybe, I understood something wrong, but I thought that the
> above 'webserver' script would replace apache in my case; at
> least I hoped!?
>
> Greetings!
>  Fabian

Oh yes...Your script is supposed to replace apache. I tried with your
script on my pc and its working just fine. However the problem still is
that the server is taking your file to be a plain file rather than a
CGI script. Looking at CGIHTTPServer.is_cgi method might prove helpful.

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


Re: Really strange behavior

2006-11-04 Thread ArdPy

IloChab wrote:
> Sorry I wasn't able to be more specific on my topic but I really do not
> know how to classify my  problem, I mean that I can't understand if it's
> a python
> or a twisted
> or a Qt4
> problem
> I'm trying to run a simple application with Twisted and Qt4.
> To do this I downloaded this:
> http://twistedmatrix.com/trac/attachment/ticket/1770/qt4reactor.py
> Now,
> if I run this:
> # >
> import  qt4reactor
> import sys
> from PyQt4 import  QtGui
> from winIum import Window
>
> def main():
> app = QtGui.QApplication(sys.argv)
> qt4reactor.install(app)
> MainWindow = QtGui.QMainWindow()
> win = Window(MainWindow)
> MainWindow.show()
> from twisted.internet import reactor
> reactor.run()
> # 
> my window shows and run correctly.
>
> If I run this:
> # >
> import  qt4reactor
> import sys
> from PyQt4 import  QtGui
> from winIum import Window
>
> def creApp():
> app = QtGui.QApplication(sys.argv)
> qt4reactor.install(app)
> retrun app
> def creWin():
> MainWindow = QtGui.QMainWindow()
> win = Window(MainWindow)
> MainWindow.show()
> def main():
> app = creApp()
> creWin()
> from twisted.internet import reactor
> reactor.run()
> # <
> my window doesn't show and the script doesn't stop but remains trapped in
> some gui loop.
>
> What's the problem I can't see??
>
> Thank you in advance for any help.
> Licia

Well the only problem according to me could be with the 'from
twisted.internet import reactor' statement.
Try putting this at the beginning of the script. Might be it will work
just fine...

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


Re: Learning Python

2006-11-06 Thread ArdPy

kaushal wrote:
> Hi
>
> How do i start Learning Python,is there any reference material which I
> can refer since I dont have
> any programming experience
>
> Thanks and Regards
>
> Kaushal

Hi kaushal,

Look into http://diveintopython.org. Dive into python is a really
readable ebook...enjoy

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


Help me understand this

2007-01-29 Thread ArdPy
Hi,

Pls tell me whats going on in the code snippet below:

>>> n = 10
>>> statstr = "N = ",n
>>> type(statstr) #case1

>>> print statstr
('N = ', 10)
>>> print "N = ",n   #case 2
N =  10

In the first case the result is printed as a tuple and in the second 
it appears as an ordinary string.

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