[Tutor] Iron Python

2006-03-04 Thread ryan luna
Hello, i have a question about Iron Python, what
exactly does it do? i know its something about .net
but i still dont understand exactly what it does, To
use it do you still write your scripts in the Python
IDLE, or what 0-o,
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iron Python

2006-03-04 Thread andrew clarke
On Sat, Mar 04, 2006 at 12:21:56AM -0800, ryan luna wrote:

> Hello, i have a question about Iron Python, what exactly does it do?
> i know its something about .net but i still dont understand exactly
> what it does, To use it do you still write your scripts in the Python
> IDLE, or what 0-o,

It's Microsoft's version of Python (written in C#) that runs on top of
the .NET Framework, so it can generate .exe files for .NET, among other
things.

A short demo:

D:\devel\IronPython>IronPythonConsole.exe
IronPython 1.0.2237 (Beta) on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
>>> print "Hello world."
Hello world.
>>> ^Z

D:\devel\IronPython>type hello.py
print "Hello world."

D:\devel\IronPython>IronPythonConsole.exe hello.py
Hello world.

D:\devel\IronPython>IronPythonConsole.exe -O -X:SaveAssemblies hello.py
Hello world.

D:\devel\IronPython>dir hello.exe
 Directory of D:\devel\IronPython

2006-03-04  20:16 3,072 hello.exe

D:\devel\IronPython>hello.exe
Hello world.

Regards
Anderw
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Pyexe

2006-03-04 Thread ryan luna
Hello, Call me a complete n00b but i dont understand
how to get Pyexe to work,
Iv read the site and kinda just confuses me, as you
can prolly tell im still pretty new to programming,
What exactly do i have to do with pyexe to make python
scripts exacutables.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iron Python

2006-03-04 Thread Basem Narmok
ryan luna wrote:

> Hello, i have a question about Iron Python, what
> exactly does it do? i know its something about .net
> but i still dont understand exactly what it does, To
> use it do you still write your scripts in the Python
> IDLE, or what 0-o,
>
Hi Ryan,

http://msdn.microsoft.com/msdntv/episode.aspx?xml=episodes/en/20051110PythonJH/manifest.xml
 


Have fun
Basem Narmok
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Urgent - Using Threads for processing each single Packet ?

2006-03-04 Thread Liam Clarke
Hi Sudarshana,

Out of curiosity, what are you building that requires you post 500
pages to a server at once?
I apologise if the question is intrusive, but I can think of a few
appns that involve that, and none of them are good.

Regards,

Liam Clarke

On 3/4/06, Sudarshana KS <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> Currently i am planning for writing a tool which gets a webpage and
> fills the appropriate fields and posts the page back to the server.
> The problem is that i am using SCAPY for doing http as i need VLAN TAG
> to be supported to get the HTTP Page.
>
> So before starting this i had couple of questions.
>
> 1. As we need to establish a TCP session for http to work , do we need
> to process each packet as a seperate thread ? I am not sure how the
> system would respond if we have to get 500 webpages - in the sense the
> total number of tcp connection is around 500 . Could any body tell me
> what would be best design ? Using each thread for single packet
> processing is it worth ?
>
> 2. Is there any specific tool or any built in APIs which can parse
> Http part of the packet ?
>
> Please help me .
> Thanks in advance,
>
> Sudarshana K S
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pyexe

2006-03-04 Thread Liam Clarke
Hi Ryan,

It took me about a year to cotton onto it as well.

So, I wrote a script for my friend, and wanted to send it as an exe.

The script I wrote was called disco_spider.py.

I assume you've installed py2exe?

What I then had to do was create another Python script called setup.py
in the same directory as disco_spider.py, this is what setup.py looks
like:


from distutils.core import setup
import py2exe

setup(
# The first three parameters are not required, if at least a
# 'version' is given, then a versioninfo resource is built from
# them and added to the executables.
version = "0.5.0",
description = "Custom built copier of things.",
name = "Disco Spider",

# targets to build
console = ["disco_spider.py"]
)


After that, I open up a DOS prompt, and go to the directory
disco_spider.py and setup.py are in and I type:

python setup.py py2exe

at the command prompt. This runs py2exe, which, if everything goes
well, creates a subfolder called dist. Everything in dist is what you
need to distribute your script.

Good luck,

Liam Clarke

On 3/4/06, ryan luna <[EMAIL PROTECTED]> wrote:
> Hello, Call me a complete n00b but i dont understand
> how to get Pyexe to work,
> Iv read the site and kinda just confuses me, as you
> can prolly tell im still pretty new to programming,
> What exactly do i have to do with pyexe to make python
> scripts exacutables.
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Editing Pickled .dat files

2006-03-04 Thread ryan luna
Hello, this is like my 3rd question today lol which is
making up for not asking any for months =P, anyways
I have a pickled .dat file named dictionary, maybe
youv guessed this but its a dictionary of the
Alphabet, the program is a translator right now all it
does is translate the Alpabet (its a stupid made up
language helping someone out cuz i needed a project)
anyways im pretty sure i have the reading the pickled
file, taking input from the user, looking on the word
in the .dat file and printing out the translation, 
Here is where im stuck.
I want the program to be able to translate full words
to (the only way i know to do that is to put every
word in the dictionary, aka .dat file)
im not goin to put all the english words and there
translation in there myself! so i have a option for
the user to put there own definitions,
What i need to know is how do i take input from the
user, collect the word and its definitions and then
pickle it into the .dat but editing the dictionary in
the .dat file.
heres my code for reading so you get a better idea of
what i mean

pickle_file = open("dictionary.dat", "r")
dictionary = cPickle.load(pickle_file)
while sentence != "0":
sentence = raw_input("\nInput a english
letter/word to be translated: ")
if sentence in dictionary:
definition = dictionary[sentence]
print "\n", definition

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutorial for creating web server

2006-03-04 Thread Kent Johnson
Rakesh Mishra wrote:
> Even you not clear than simply in one word I wanted to built Apache web 
> server in python.

If you really want to write Apache from scratch in Python you have a lot 
of learning and a lot of work to do. A good starting point might be the 
book Foundations of Python Network Programming.
http://apress.com/book/bookDisplay.html?bID=363

You will also need to understand HTTP protocol, I'm sure Google can help 
there. The reference for HTTP is RFC 2068:
http://www.freesoft.org/CIE/RFC/2068/index.htm

But why do you want to do this? There are several excellent Python 
webservers available. If your goal is to create a home page, this is the 
hard way to do it.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] One shared object. class attribute or global variable?

2006-03-04 Thread Alan Gauld
> I've got a module that needs to share a pack of cards
>
> pack = ["14s", "2s", "3s", "4s", "5s", "6s", "7s", "8s", "9s", "10s", 
> "11s",
> ...
> random.shuffle(pack)
>
> do you think it is worth making a class with just this attribute
> or would this be a good place to use a global variable?

Classes with single attributes are almost never the right thing.
The question is what does the class *do*?
What are its responsibilities within the application?

You've already suggested that it could shuffle itself.
Maybe it could deal a random card too?
Maybe it could tell you something about how many cards are left?
Or whether a particular card is in the pack?

In that case creating a class makers sense. Classes without behaviour
are rarely useful. Data without fiunction is rare. Data and function is a 
class.

So if its only a bit of data themn sure make it a module level variable.
But ifd you are writing functions that operate on that data consider
makng it a class. Particul;arly if there could ever arise the need for
more than one pack - a game of Spider or Cribbage for example?

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld






___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Editing Pickled .dat files

2006-03-04 Thread Liam Clarke
Hi Ryan,

Technically, you don't.

You haul your dictionary out, as you're doing here -

dictionary = cPickle.load(pickle_file)

And when you're finished, you pickle it again.

Regards,

Liam Clarke

On 3/5/06, ryan luna <[EMAIL PROTECTED]> wrote:
> Hello, this is like my 3rd question today lol which is
> making up for not asking any for months =P, anyways
> I have a pickled .dat file named dictionary, maybe
> youv guessed this but its a dictionary of the
> Alphabet, the program is a translator right now all it
> does is translate the Alpabet (its a stupid made up
> language helping someone out cuz i needed a project)
> anyways im pretty sure i have the reading the pickled
> file, taking input from the user, looking on the word
> in the .dat file and printing out the translation,
> Here is where im stuck.
> I want the program to be able to translate full words
> to (the only way i know to do that is to put every
> word in the dictionary, aka .dat file)
> im not goin to put all the english words and there
> translation in there myself! so i have a option for
> the user to put there own definitions,
> What i need to know is how do i take input from the
> user, collect the word and its definitions and then
> pickle it into the .dat but editing the dictionary in
> the .dat file.
> heres my code for reading so you get a better idea of
> what i mean
>
> pickle_file = open("dictionary.dat", "r")
> dictionary = cPickle.load(pickle_file)
> while sentence != "0":
> sentence = raw_input("\nInput a english
> letter/word to be translated: ")
> if sentence in dictionary:
> definition = dictionary[sentence]
> print "\n", definition
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Editing Pickled .dat files

2006-03-04 Thread ryan luna
Hey, thanks for the help but when i try i get a error
Bad file descripter, here is the code im using

elif choice == "2":
pickle_file = open("dictionary.dat", "a")
sentence = raw_input("Enter the word youd like
to add: ")
if sentence not in pickle_file:
definition = raw_input("Whats the
translated version: ")
pickle_file[sentence] = definition
print "\n\t'",sentence,"'", "Has been
added to the dictionary."
else:
print "\n\tThat term already exists!"

--- Liam Clarke <[EMAIL PROTECTED]> wrote:

> Hi Ryan,
> 
> Technically, you don't.
> 
> You haul your dictionary out, as you're doing here -
> 
> dictionary = cPickle.load(pickle_file)
> 
> And when you're finished, you pickle it again.
> 
> Regards,
> 
> Liam Clarke
> 
> On 3/5/06, ryan luna <[EMAIL PROTECTED]> wrote:
> > Hello, this is like my 3rd question today lol
> which is
> > making up for not asking any for months =P,
> anyways
> > I have a pickled .dat file named dictionary, maybe
> > youv guessed this but its a dictionary of the
> > Alphabet, the program is a translator right now
> all it
> > does is translate the Alpabet (its a stupid made
> up
> > language helping someone out cuz i needed a
> project)
> > anyways im pretty sure i have the reading the
> pickled
> > file, taking input from the user, looking on the
> word
> > in the .dat file and printing out the translation,
> > Here is where im stuck.
> > I want the program to be able to translate full
> words
> > to (the only way i know to do that is to put every
> > word in the dictionary, aka .dat file)
> > im not goin to put all the english words and there
> > translation in there myself! so i have a option
> for
> > the user to put there own definitions,
> > What i need to know is how do i take input from
> the
> > user, collect the word and its definitions and
> then
> > pickle it into the .dat but editing the dictionary
> in
> > the .dat file.
> > heres my code for reading so you get a better idea
> of
> > what i mean
> >
> > pickle_file = open("dictionary.dat", "r")
> > dictionary = cPickle.load(pickle_file)
> > while sentence != "0":
> > sentence = raw_input("\nInput a
> english
> > letter/word to be translated: ")
> > if sentence in dictionary:
> > definition = dictionary[sentence]
> > print "\n", definition
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pyexe

2006-03-04 Thread Alan Gauld
> Hello, Call me a complete n00b but i dont understand
> how to get Pyexe to work,

That's probably because py2exe isn't really aimed at beginners. 
Its moderately complex to use. That's because most programmers 
don't need it.

> Iv read the site and kinda just confuses me, as you
> can prolly tell im still pretty new to programming,
> What exactly do i have to do with pyexe to make python
> scripts exacutables.

To make a script executable you just need to make it readable 
and then double click on it./ Windows will find the python 
interpreter and execute the script for you. No need for py2exe.
You only need py2exe if you really need to create a standalone 
exe file that yoiu can distribute without the need for python to 
be installed. The result will be a largish file incorporating the 
python interpreter and all your modules in a single file.

If you really need that then you will need to tell us what you are
doing with py2exe, where it seems to be going wrong and then 
someone can provide an answer...

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Editing Pickled .dat files

2006-03-04 Thread Liam Clarke
Hi Ryan,

You're trying to use your file, dictionary.dat like a dictionary data
structure in Python.
They don't work the same way.

So.

pickle_file = open("dictionary.dat", "r")
dictionary = cPickle.load(pickle_file)
pickle_file.close()

elif choice == "2":
 pickle_file = open("dictionary.dat", "a")
sentence = raw_input("Enter the word youd like to add: ")
if sentence not in dictionary:
 definition = raw_input("Whats the translated version: ")
  dictionary[sentence] = definition
 print "\n\t'",sentence,"'", "Has been added to the dictionary."
 else:
 print "\n\tThat term already exists!"


Once you're done, you just "repickle" the dictionary.

pickle_file = open("dictionary.dat", "w") #Opened in write mode
cPickle.dump(dictionary, pickle_file)
pickle_file.close()

Regards,

Liam Clarke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Editing Pickled .dat files

2006-03-04 Thread ryan luna
Ohhh ok i got it to work! but why isn't the change
permanent? it is "writing" to the file isn't it.

--- Liam Clarke <[EMAIL PROTECTED]> wrote:

> Hi Ryan,
> 
> You're trying to use your file, dictionary.dat like
> a dictionary data
> structure in Python.
> They don't work the same way.
> 
> So.
> 
> pickle_file = open("dictionary.dat", "r")
> dictionary = cPickle.load(pickle_file)
> pickle_file.close()
> 
> elif choice == "2":
>  pickle_file = open("dictionary.dat", "a")
> sentence = raw_input("Enter the word youd
> like to add: ")
> if sentence not in dictionary:
>  definition = raw_input("Whats the
> translated version: ")
>   dictionary[sentence] = definition
>  print "\n\t'",sentence,"'", "Has been
> added to the dictionary."
>  else:
>  print "\n\tThat term already exists!"
> 
> 
> Once you're done, you just "repickle" the
> dictionary.
> 
> pickle_file = open("dictionary.dat", "w") #Opened in
> write mode
> cPickle.dump(dictionary, pickle_file)
> pickle_file.close()
> 
> Regards,
> 
> Liam Clarke
> 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to get the return value?

2006-03-04 Thread Ingo
To make a time lapse video I've been playing with the sched module.
There is one problem I run into, in the code below, how do I get the
returned value t from printtime into main? 


import time
from sched import scheduler

class time_lapse(scheduler):

def time_lapse(self, start_time, stop_time, interval, priority,
action, argument):
def lapse():
action(*argument)
i=self.enter(interval, priority, lapse, ())
if stop_time:
if stop_timehttp://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to get the return value?

2006-03-04 Thread Anna Ravenscroft
On 3/4/06, Ingo <[EMAIL PROTECTED]> wrote:
To make a time lapse video I've been playing with the sched module.There is one problem I run into, in the code below, how do I get thereturned value t from printtime into main?import timefrom sched import scheduler
class time_lapse(scheduler):def time_lapse(self, start_time, stop_time, interval, priority,action, argument):def lapse():action(*argument)i=self.enter(interval, priority, lapse, ())
if stop_time:if stop_timeself.cancel(i)self.enterabs(start_time, priority, lapse, ())def printtime(strf=None):t=time.time
()if strf:print time.strftime("%Y%m%d_%H%M%S")else:print time.localtime()return tdef main():schedule = time_lapse(time.time, time.sleep)start=
time.time()stop=list(time.localtime(start))stop[3]=stop[3]+2stop=time.mktime(stop)#schedule.time_lapse(None,None,5,1,printtime,()) #start now, runforeverschedule.time_lapse(start,stop,7,0,printtime,(1,))
schedule.run()if __name__ == "__main__":main()Ingo___Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
main(printtime(strf=None))

should do it. Alternately:

tt = printtime(strf=None)
main(tt)

Anna
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutorial for creating web server

2006-03-04 Thread w chun
>  i wanted to create my own web server, can any body suggest any tutorial,
>  by the way i have gone through book Core Python Programing, in this book
>  one example is given but it is to abstract, that i am unable to understand


rakesh,

1) based on this thread and responses from various folks, it sounds
like you are only interested in publishing your home page (currently
in PHP).  if you have just static web pages (no CGI, etc.), then you
do not need anything nearly as powerful as the Zope webserver nor
Apache.  Python's generic webservers are good enough for this, and you
don't even have to know Python to run them.

2) which example in Core Python confuses you?  i'll assume it's
Example 19.7.  this example is really only necessary if you want to
start writing a full-fledged server (similar to the ones already
mentioned).  if you want to just serve web pages (and even process
CGI), here's a webserver for you that you should understand:

from CGIHTTPServer import test;test()

put this code into a script... say webserver.py and put it into the
same directory or folder as your .HTML files.  then run "python
webserver.py".  you should then be able to access your web pages by
surfing to http://localhost:8000/myWebPage.html (or whatever it's
called).

i think that i'll add an example like this to the book too, in case
there are others that want to just serve pages and perhaps practice
their CGI skills.

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2006,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Delete in .dat

2006-03-04 Thread ryan luna
My question seems like itd be farly simple but i cant
seem to get it to work,
My .dat file is a dictionary and i need to be able to
only delete a single word and its definition,
heres what i have so far but it doesn't work.

pickle_file = open("dictionary.dat", "r")
dictionary = cPickle.load(pickle_file)
pickle_file.close()
sentence = raw_input("What definition would
you like to delete?: ")
if sentence in dictionary:
del dictionary[sentence]
print "\n\t", sentence, "Has been removed"
else:
print "\n\t", sentence, "That word is not
in the dictionary"
pickle_file = open("dictionary.dat", "w")
cPickle.dump(dictionary, pickle_file)
pickle_file.close()

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Delete in .dat

2006-03-04 Thread Danny Yoo


On Sat, 4 Mar 2006, ryan luna wrote:

> My question seems like itd be farly simple but i cant seem to get it to
> work, My .dat file is a dictionary and i need to be able to only delete
> a single word and its definition, heres what i have so far but it
> doesn't work.

Hi Ryan,

By "doesn't work", what happens?  Do you get an error message, or ...?
The more details here the better, since we really are not sure what the
cause of the problem is yet.


> pickle_file = open("dictionary.dat", "r")
   ^^^

This looks somewhat suspicious.  pickle files are meant to be stored in
binary files, so you may need to open the file in binary mode:

pickle_file = open("dictionary.dat", "rb")

Otherwise, bad things may happen, especially on Windows platforms.


Good luck to you!

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor