Re: [Tutor] iterating data and populating a dictionary

2008-08-05 Thread Monika Jisswel
oops i forgot to count lines, MainDictionary = {} N = 0 M = 0 for line in open('data_file', 'r'): if line: if M < 3: N += 1 M += 1 a, b = line.split(" = ") # "=" is in between spaces whish gives you only two variables. if a == 'Field':

Re: [Tutor] iterating data and populating a dictionary

2008-08-05 Thread Monika Jisswel
maybe this can help MainDictionary = {} N = 0 for line in open('data_file', 'r'): if line: N += 1 a, b = line.split(" = ") # "=" is in between spaces whish gives you only two variables. if a == 'Field': MainDictionary[N] == {} elif a == 'Index':

Re: [Tutor] regular expressions

2008-08-05 Thread Monika Jisswel
here is what my interpreter gives : >>> >>> >>> text = "Bill Smith is nice" >>> print text Bill Smith is nice >>> re.sub('Smith', '', text) 'Bill is nice' >>> text = "Jim likes a girl (Susan)" >>> print text Jim likes a girl (Susan) >>> KeyboardInterrupt >>> re.sub('(Susan)', '', text) 'Jim likes

Re: [Tutor] removing whole numbers from text

2008-08-05 Thread Monika Jisswel
[EMAIL PROTECTED] ~]# python Python 2.5.1 (r251:54863, Nov 23 2007, 16:16:53) [GCC 4.1.1 20070105 (Red Hat 4.1.1-51)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> import re >>> >>> a = 'this is a simple 3xampl3 of 2 or 3 numb3rs' # some text >>> b = re.su

Re: [Tutor] Is anybody out there who could help me with URL Authentication?

2008-08-01 Thread Monika Jisswel
Here is some code, it will help you manage cookies, & stay logged in to the website for further queries. import os, sys, time, urllib, urllib2, cookielib, re > > cj=cookielib.LWPCookieJar() > headers={'User-Agent' : user_agent} > opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) > urlli

Re: [Tutor] Tutor Newbie

2008-08-01 Thread Monika Jisswel
it would take learning to use some of the modules that help create GUIs. they are : wx and Tkinter 2008/7/25 Sam Last Name <[EMAIL PROTECTED]> > Hey guys, need some info on "programs" :) > > > Heres a Very simple Script that works with basically any numbers. > > > width = input("What is the Width

Re: [Tutor] Newbie

2008-08-01 Thread Monika Jisswel
if you remove the comma after the print i for i in range(10) : print i print "Goodbye World!" your problem will be solved, the comma in a print statement means ' ' or space. THREADING is a word that means something else than having two strings on the same line. 2008/7/23 Sam Last Name <

Re: [Tutor] Unzipping a list

2008-08-01 Thread Monika Jisswel
> > >>> answers= ['ask','tell','repeat','sell'] > >>> > >>> > >>> a = '/usr/program/bin -o '+ ' '.join(answers) > >>> print a > /usr/program/bin -o ask tell repeat sell > 2008/7/8 Faheem <[EMAIL PROTECTED]>: > Hey all, > > If anyone is interested I found this while googling > > answers= ['ask'.'t

Re: [Tutor] how do I create a lists of values associated with a key?

2008-08-01 Thread Monika Jisswel
2008/8/1 Angela Yang <[EMAIL PROTECTED]> > > > collection = [] > collection['abby'].append('apprentice1') > collection['abby'].append('apprentice2') > > That did not work because list index is not numeric. > But for dictionaries, it is key - value pairs. But I need key -> multiple > values. > > D

Re: [Tutor] Reading List from File

2008-07-31 Thread Monika Jisswel
oops it is reader not Reader (all lower case), so this line : data = csv.Reader(myfile, delimeter = ',') should be data = csv.reader(myfile, delimeter = ',') 2008/7/31 S Python <[EMAIL PROTECTED]> > Hi Everyone, > > Thanks for the variety of responses in such a short amount of time. > This distr

Re: [Tutor] To Specify a directory path to download

2008-07-31 Thread Monika Jisswel
> > urllib.urlretrieve(url.strip(),save_to) > could be changed into this : folder = '/home/html-data/' urllib.urlretrieve(url.strip(),folder+save_to) 2008/7/31 swati jarial <[EMAIL PROTECTED]> > Hello, > > I am new to python this is the code I have written to download a file from > the internet

Re: [Tutor] Reading List from File

2008-07-31 Thread Monika Jisswel
Emile is right, in python you can do most of the stuff yourself by hand coding it, or you can use pre-made bullet proof and ready to go modules, here you can go for the csv module that comes part of the standard library. import csv myfile = open('file', 'r') # open file for reading data = csv.Rea

Re: [Tutor] Communication between threads

2008-07-31 Thread Monika Jisswel
> > I'm looking for some thoughts on how two separate threads can > communicate in Python > You will probably get out of your doubts by reading about the SocketServer module and SocketServer.ThreadingTCPServer class. Once your get a server up & running you can run parallel threads, from there you

Re: [Tutor] key/value order in dictionaries

2008-07-31 Thread Monika Jisswel
Python dictionaries are not ordered & the order you will get when you print a dictionary is the order that the python virtual machines thinks optimal for that dictionary for its own internal procedures. ___ Tutor maillist - Tutor@python.org http://mail.

Re: [Tutor] Check for file in different dirs

2008-07-25 Thread Monika Jisswel
> > for f in file1 file2 file3 file4 file5: > a = os.path.exists('/home/dir1/file.txt') > b = os.path.exists('/home/dir2/file.txt') > c = os.path.exists('/home/dir3/file.txt') > if a and b and c: > do ... > elif a and b : > do ... > elif a : > do

Re: [Tutor] question about socket status

2008-07-24 Thread Monika Jisswel
if networking code is inside of the kernel then its from the kernel that you can get network information & nowhere else. (http://www.linuxdevcenter.com/pub/a/linux/2000/11/16/LinuxAdmin.html) I would just add that to see what ne

Re: [Tutor] Raw string

2008-07-21 Thread Monika Jisswel
> > I don't know in advance what the file name will be... import re for line in myfile: if re.search(r'\', line): line = line.replace('\\', '') if you have lines that contain a \ in them that you don't want to substitute then you need another if statement. ___

Re: [Tutor] Raw string

2008-07-21 Thread Monika Jisswel
> > Thanks, > I am aware of goodies that raw string offers, but my question was how to > use it with variable that already contains string. :) > if you are reading the value from a file : import re for line in myfile: if re.search(r'e:\mm tests\1. exp files\5.MOC-1012.exp', line): l

Re: [Tutor] Raw string

2008-07-21 Thread Monika Jisswel
instead of s='e:\mm tests\1. exp files\5.MOC-1012.exp' try to use : s = r'e:\mm tests\1. exp files\5.MOC-1012.exp'.replace('\\', '') for me here is what it gives: >>> s = r'e:\mm tests\1. exp files\5.MOC-1012.exp'.replace('\\', '') >>> print s e:\\mm tests\\1. exp files\\5.MOC-1012.exp >>

Re: [Tutor] continuouse loop

2008-07-19 Thread Monika Jisswel
Thanks or your replies, in fact I need my server to recieve queries from some 40 clients, process the recieved text (some calculations) & send a response back to them, in my previouse application I used a database, (they entered thier queries into the db & my calculating script looks at new records

Re: [Tutor] Any way of monitoring a python program's memory utilization?

2008-07-17 Thread Monika Jisswel
I m really sorry if no one of you liked/agreed with the fridge analogy but that's what my brain could come up with at the time, I have to say it's not a very scientific argument. but I only meant to say that if you are piping data into memory & this data is larger than that memory then there is no

[Tutor] continuouse loop

2008-07-17 Thread Monika Jisswel
Would a program using a continuouse loop such as in this code take up resources on the system if left for long period ? import sys > > while 1: > self.data = sys.stdin.readline() > self.function_1(data) > What are my other options is I want to have a running program & other programs commu

Re: [Tutor] Any way of monitoring a python program's memory utilization?

2008-07-17 Thread Monika Jisswel
I see no problem, if you open very BIG files then your memory will get filled up & your system will halt, can you buy more food than your fridge can handle , and write to a list asking to invistigate the problem ? 2008/7/17 Terry Carroll <[EMAIL PROTECTED]>: > On Thu, 17 Jul 2008, M

Re: [Tutor] Any way of monitoring a python program's memory utilization?

2008-07-17 Thread Monika Jisswel
> > I'm iterating through a vey large tarfile (uncompressed, it would be about > 2.4G, with about 2.5 million files in it) and I can see from some external > monitors that its virtual storage usage just grows and grows, until my > whole system finally grinds to a halt after about 1.2 million member

Re: [Tutor] function for memory usage

2008-07-15 Thread Monika Jisswel
ps -eo pid,ppid,rss,vsize,pcpu,pmem,cmd -ww --sort=pid I m no genius i found it here : http://mail.nl.linux.org/linux-mm/2003-03/msg00077.html ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] parsing sendmail logs

2008-07-15 Thread Monika Jisswel
> > but in that case use bash or ksh Hi Alan, to say the truth I never thought about "additional overhead of getting the input/output data transferred" because the suprocess itself will contain the (bash)pipe to redirect output to the next utility used not the python subprocess.PIPE pipe so it

Re: [Tutor] parsing sendmail logs

2008-07-14 Thread Monika Jisswel
lire & logethy are an option. but if you want to go on your own I believe awk, grep, sort are extremely extremely extremely (yes 3 times !) powerfulI tools, so giving them up is a bad decision I guess either talking about thier speed or what they would allow you to do in few lines of code. so w

Re: [Tutor] build list of non-empty variables

2008-07-08 Thread Monika Jisswel
list comprehention : [ x for x in LIST if x != '' ] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How to create array of variants?

2008-07-08 Thread Monika Jisswel
Comment : I never did any VB so I am not sure if I understand you. supposing your data comes like this : python code : Data = ( ('A', 1), ('B', 2), ('C', 3), ('D', 4) ) > #you can create a list of the items like this : > > List_Letters = [ x[0] for x in Data] > List_Numbers = [ x[1] for x in Dat

Re: [Tutor] file object in memory

2008-07-07 Thread Monika Jisswel
values ( 11, 22, 33)' & pipe it to mysql directly, it will be slow for tasks like a load but i don't deal with more than 4000 per time & thats every 15 Minutes. 2008/7/7 Martin Walsh <[EMAIL PROTECTED]>: > Monika Jisswel wrote: > > You know bob, you ar

Re: [Tutor] New to pythong

2008-07-07 Thread Monika Jisswel
you can start with stuff you need like, for example write a program that scans your hard disk & tells you the details about pdf, jpg, zip, avi files that you have, with creation date and sizes. when you need help write us. ___ Tutor maillist - Tutor@py

Re: [Tutor] graphs & diagrams in python

2008-07-07 Thread Monika Jisswel
hnson <[EMAIL PROTECTED]>: > On Sat, Jul 5, 2008 at 9:16 AM, Kent Johnson <[EMAIL PROTECTED]> wrote: > > On Fri, Jul 4, 2008 at 3:54 PM, Monika Jisswel > > <[EMAIL PROTECTED]> wrote: > >> Hi Again, > >> > >> What is the best library for dr

Re: [Tutor] my first object model, using an interface

2008-07-06 Thread Monika Jisswel
This looks like a database driven application. When you send a package you must save the event on a database. When a HomeWork is submited it must be entered in the database. When you need to see what's the situation of any one student or all students you just query teh database. so you would be bet

Re: [Tutor] Exploring the Standard Library

2008-07-05 Thread Monika Jisswel
import sys print sys.path but no one recommends starting with python from there. you're better of reading the python.org/doc files. 2008/7/5 Nathan Farrar <[EMAIL PROTECTED]>: > I'd like to spend some time exploring the standard library. I'm running > python on Ubuntu. How would I find the

Re: [Tutor] loops, variables and strings

2008-07-05 Thread Monika Jisswel
maybe StringIO ? MsgBody = StringIO.StringIO() print >> MsgBody, "Hello. Below is an automated e-mail with important statistics." print >> MsgBody, ""#empty line print >> MsgBody, ""#empty line print >> MsgBody, "The following user accounts expired today:" print >> MsgBody, " - " %

Re: [Tutor] Script Name/Path Information

2008-07-05 Thread Monika Jisswel
import sys #a module that gives access to the system import os#a module that gives access to the os print sys.argv[0] #prints file name of the script print os.getcwd() #print current working directory print os.getcwd()+sys.argv[0] # 2008/7/5 Nathan Farrar <[EMAIL PROTECTED]>

Re: [Tutor] file object in memory

2008-07-04 Thread Monika Jisswel
You know bob, you are very clever, I have used RAM disk for realtime recording of audio before but it never occured to me to use it for light jobs like this one, I just compeletely ignored it as an option & by the way this openes a lot of doors for many of my other programs. but wouldn't it be ver

Re: [Tutor] directory traversal help

2008-07-04 Thread Monika Jisswel
the fact that it fails shoul be due to some windows restriction about trash & some hidden files, to bypass that you can add a filter in here def walk(dir): for name in os.listdir(dir): #the following line is the filter if name != 'Trash can' or name != 'some hidden directory name':

[Tutor] graphs & diagrams in python

2008-07-04 Thread Monika Jisswel
Hi Again, What is the best library for drawing graphs & diagrams to ilustrate some statistics ? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Init Scripts

2008-07-04 Thread Monika Jisswel
IMHO the Linux OS itself relays heavily on python in some way or the other, but as far as the boot process is concerned I think you should consider the fact that it was engeneered by very smart poeple, very security aware poeple, so you will have to give a really good ALTERNATIVE to thier engeneeri

Re: [Tutor] open-file GUI

2008-07-04 Thread Monika Jisswel
Go for wxPython, they have a pretty good tutorial on thier website ( wxpython.org) If you can use Python_Numpy_Scipy_Matplotlib then I can assure you that you will learn wxpython in a matter of minutes. > > 2008/7/4 Eli Brosh <[EMAIL PROTECTED]>: > >> Hello, >> I am starting to use Python+NumP

[Tutor] file object in memory

2008-07-04 Thread Monika Jisswel
Hi everyone, In my program I have this code : self.run_cmd_0 = subprocess.Popen(self.cmd_0, stdout = subprocess.PIPE, > shell = True) #(1) > self.run_cmd_1 = subprocess.Popen(self.TOCOL, stdin = > self.run_cmd_0.stdout, stdout = subprocess.PIPE, shell = True)#(2) > self.result_0 = StringI

Re: [Tutor] Question about string

2008-07-03 Thread Monika Jisswel
Python is one of the smartest languages, it does many things for the programmer (I don't know but this might be what they mean with Batteries-Included) , & you have just scratched the surface of it, here python concatenated your strings together for you, later you will meet list comprehention & o

Re: [Tutor] web programming tutorials?

2008-04-20 Thread Monika Jisswel
Hi, Ok, so if you were to go back in time ... which pythonic web-tool /framework would you put more time in studying ? keep in mind that you still have no experience and you need something to get you started in web technology, second thing to take into account is that it doesn't have to be a

Re: [Tutor] urllib2.urlopen(url)

2008-04-20 Thread Monika Jisswel
nika. 2008/4/20, Martin Walsh <[EMAIL PROTECTED]>: > > Monika Jisswel wrote: > > Hi, > > > > can i stop urllib2.urlopen() from following redirects automatically ? > > > It doesn't answer your question directly, but if you care more about the > initial request

Re: [Tutor] web programming tutorials?

2008-04-18 Thread Monika Jisswel
> > and has a huge community, it is a very advanced framework. > Ok but I still need more votes for zope to be convinced, Just in case Zope won the majority of the voices ... How much time would it take one to learn & become productive in zope ? ___ Tuto

Re: [Tutor] web programming tutorials?

2008-04-18 Thread Monika Jisswel
Hi, reading theses emails i have a question : ikaaro or zope - what's best ? which one is the most used ? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] urllib2.urlopen(url)

2008-04-18 Thread Monika Jisswel
Hi, can i stop urllib2.urlopen() from following redirects automatically ? one more question i had in mind, the function urllib2.urlopen.geturl() does get me what i want but does it do the download of the page i was redirected to ? or just downloads the initial page that actually does the redir