Re: [Tutor] Structure of my simulation / monte-carlo

2009-11-01 Thread Dave Angel
Kent Johnson wrote: On Sun, Nov 1, 2009 at 10:47 AM, Vincent Davis wrote: Kent Johsnon writes "This class has a lot of responsibilities: - create applicants - create institutions - run a single match - run multiple matches - calculate statistics on the result of multiple matches A principle

Re: [Tutor] Structure of my simulation / monte-carlo

2009-11-01 Thread Dave Angel
Dave Angel wrote: Kent Johnson wrote: On Sun, Nov 1, 2009 at 10:47 AM, Vincent Davis wrote: Kent Johsnon writes "This class has a lot of responsibilities: - create applicants - create institutions - run a single match - run multiple matches - calculate statistics on the result of mul

Re: [Tutor] Adding Value to CSV

2009-11-02 Thread Dave Angel
en to the CSV file: '"152.88.91.98","BitTorrent Client Activity","1","2009-09-23 15:40:33", "Part of DHCP Pool" Thanx in advance for the help. On Sun, Nov 1, 2009 at 7:16 AM, Dave Angel wrote: Paras K. wrote: I have some code that is g

Re: [Tutor] Retrieving information from a plain text file (WinXP/py2.6.2/Beginner)

2009-11-02 Thread Dave Angel
(Looks like maybe you hijacked another thread, instead of just creating a new message, with new topic, for the list) Katt wrote: Hello all, Thank you all for your help. I appreciate it alot. I have been trying to work with file IO alot recently and would like to improve my little program so

Re: [Tutor] trouble using 2to3.py

2009-11-03 Thread Dave Angel
(Erasing entire history, since you both top-posted, and it's too confusing) When you run a xxx.py on Windows, it locates the python.exe using the registry entries set up by assoc and ftype. But when you run "python" it looks for python.exe (or python.bat, or ...) on the PATH. So there's not

Re: [Tutor] trouble using 2to3.py

2009-11-03 Thread Dave Angel
Richard D. Moores wrote: On Tue, Nov 3, 2009 at 05:30, Dave Angel wrote: Easiest way to know which python is being used is to run it same way: e:\python31\temp> python 2to3.py -w mycalc.py Or the way I do it, have python31.bat and python26.bat, which launch the exact pythons that I w

Re: [Tutor] trouble using 2to3.py

2009-11-03 Thread Dave Angel
Tim Golden wrote: Richard D. Moores wrote: On Tue, Nov 3, 2009 at 05:30, Dave Angel wrote: Or the way I do it, have python31.bat and python26.bat, which launch the exact pythons that I want. Thanks, Dave. I'm not familiar with .bat files. Could you give me a look at one of them?

Re: [Tutor] Local vs global

2009-11-07 Thread Dave Angel
Alan Gauld wrote: "bibi midi" wrote in Although i have read up quite a lot about local and global scope in functions i still 'suffer' understanding it, ... I tried removing it but i get error variable undeclared or something. It is in the function choose_Cave. We need to see the exact erro

Re: [Tutor] Local vs global

2009-11-08 Thread Dave Angel
bibi midi wrote: On Sun, Nov 8, 2009 at 6:20 AM, bibi midi wrote: Thank you all for the helpful insights. I will keep in mind the naming rules in Python, so as not to have it in collision with Python's builtins. The mention to tidy up e.g. "compartmentalize" code is also noted. I agree de

Re: [Tutor] class initialization with a lot of parameters

2009-11-09 Thread Dave Angel
C.T. Matsumoto wrote: Hello All, I'm making a class and the parameters I'm feeding the class is getting quite large. I'm up to 8 now. Is there any rules of thumb for classes with a lot of parameters? I was thinking to put the parameters into a tuple and then in the __init__ of the class, iterate

Re: [Tutor] class initialization with a lot of parameters

2009-11-10 Thread Dave Angel
(Removing out of sequence history) DaveA instances of that class. Better than using tuples. makes sense to make a class to hold the seven parameters, and pass two If you're passing two sets of 7 parameters to the same function, it probably ___ Tuto

Re: [Tutor] Logfile multiplexing

2009-11-10 Thread Dave Angel
Stephen Nelson-Smith wrote: NameError: global name 'date' is not defined How does __iter__ know about date? Should that be self.date? S. Yes. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.p

Re: [Tutor] class initialization with a lot of parameters

2009-11-10 Thread Dave Angel
Luke Paireepinart wrote: On Tue, Nov 10, 2009 at 1:21 PM, Dave Angel wrote: (Removing out of sequence history) DaveA instances of that class. Better than using tuples. makes sense to make a class to hold the seven parameters, and pass two If you're passing two sets of 7 paramete

Re: [Tutor] Logfile multiplexing

2009-11-11 Thread Dave Angel
Stephen Nelson-Smith wrote: Hi, On Wed, Nov 11, 2009 at 10:05 AM, Alan Gauld wrote: "Stephen Nelson-Smith" wrote I don't really want to admit defeat and have a cron job sort the logs before entry. Anyone got any other ideas? Why would that be admitting defeat? Well, i

Re: [Tutor] Unexpected iterator

2009-11-12 Thread Dave Angel
Jeff R. Allen wrote: Hello, I am working my way through the tutorial, and I like trying variations, just to see what expected errors look like, and other ways things could be written. I tried a, b = 0, 0 and that worked. Then I tried this to (maybe) set both a and b to 0: a, b = 0

Re: [Tutor] How to call a method with a print statement?

2009-11-12 Thread Dave Angel
Kent Johnson wrote: On Thu, Nov 12, 2009 at 6:35 AM, Luke Paireepinart wrote: On Thu, Nov 12, 2009 at 5:29 AM, Jeff R. Allen wrote: You are looking for the __str__ method. See http://docs.python.org/reference/datamodel.html#object.__str__ Can't you also implement __repr__?

Re: [Tutor] importing variables

2009-11-12 Thread Dave Angel
Stefan Lesicnik wrote: On Thu, Nov 12, 2009 at 6:26 PM, bob gailer wrote: Stefan Lesicnik wrote: Hi guys, Im trying to do something and hit a bit of a wall, potentially im going about this the wrong way. Essentially the problem is: features file contains rt='text''' import features

Re: [Tutor] getting python 3 to run from the command line

2009-11-14 Thread Dave Angel
Khalid Al-Ghamdi wrote: Hi, for some reason I haven't been able to get python 3 to work from the the command line. I've added it to the the path in the the system variables but still no luck. when I try to run python 2.6 it works flawlessly, though, bearing in mind that it wasn't added to the sy

Re: [Tutor] opening a file directly from memory

2009-11-14 Thread Dave Angel
mj...@iol.pt wrote: I'm wondering if I must save a file to memory before opening it. By opening I mean displaying it to the user. I have a BLOB field in a db and I have managed to read the blob into a binary fileobject. I've also managed to write it to disk and then I open it by doubleclic

Re: [Tutor] Find Integer co-ordinates lying on a circle

2009-11-14 Thread Dave Angel
Shashwat Anand wrote: How to find all possible integer co-ordinates lying on a circle of given radius 'r'. If given the upper bound of 'r', I want to calculate all given co-ordinates lying for 0 <= r <= n Let's say the upper bound of radius is 5 All possible results are: radius 'r' - (x, y) 0

Re: [Tutor] Find Integer co-ordinates lying on a circle

2009-11-14 Thread Dave Angel
Shashwat Anand wrote: Your "all possible results" isn't even close to all the points that match the 0<= r <= 5. And I don't know how either spec justifies the set logic you quoted. So I have to start over. I think you're trying to find all integer co-ordinates which lie on or within

Re: [Tutor] opening a file directly from memory

2009-11-14 Thread Dave Angel
it looks promising. HTH, DaveA I know what the binary data is from the database. Typically it would be some file the OS knows how to open. Chiefly I'm trying to avoid making the user save the file on some location and then go and double click it to open it. This makes no sense, since the

Re: [Tutor] opening a file directly from memory

2009-11-15 Thread Dave Angel
to open it. This makes no sense, since the user has already made the decision to open the file. Miguel Txs Dave. You forgot to answer the question. You say "The OS knows how to open". Does *your* *program* know what program is needed, to open this particular binary data? Ye

Re: [Tutor] nul file in Windows

2009-11-15 Thread Dave Angel
Timo List wrote: For my program I disable the py2exe log feature by routing output to the nul-file. Code: if win32 and py2exe: sys.stdout = open("nul", "w") sys.stderr = open("nul", "w") This always worked fine. Today, I received an email from a user with the fo

Re: [Tutor] Find Integer co-ordinates lying on a circle

2009-11-15 Thread Dave Angel
spir wrote: Le Sun, 15 Nov 2009 09:11:16 +0530, Shashwat Anand s'exprima ainsi: No, I'm trying to find all integer co-ordinates which lies on a circle. Say for a circle of radius 5 the co-ordinates are [(5, 0), (0, 5), (-5, 0), (0, -5), (3, 4), (4,3), (3, -4), (4, -3), (-3, 4), (-4

Re: [Tutor] Iterable Understanding

2009-11-15 Thread Dave Angel
Marc Tompkins wrote: On Sun, Nov 15, 2009 at 4:11 PM, Stephen Nelson-Smith wrote: import gzip from heapq import heappush, heappop, merge Is this a preferred method, rather than just 'import heapq'? It has a couple of advantages: - convenience: if you "import heapq", then to

Re: [Tutor] GzipFile has no attribute '__exit__'

2009-11-16 Thread Dave Angel
Stephen Nelson-Smith wrote: I'm trying to write a gzipped file on the fly: merged_log = merge(*logs) with gzip.open('/tmp/merged_log.gz', 'w') as output: for stamp, line in merged_log: output.write(line) But I'm getting: Traceback (most recent call last): File "./magpie.py", lin

Re: [Tutor] proxy switcher - was Re: I love python / you guys :)

2009-11-16 Thread Dave Angel
Luke Paireepinart wrote: Here's what I knocked up over lunch. It doesn't cover the moving of the file, I don't like that it's deep-nested, and I've not tested it, but I welcome criticism and feedback: files = ['file1', 'file2', 'file3', 'file4'] settings = ['export http_proxy=', 'ftp_proxy=']

Re: [Tutor] proxy switcher - was Re: I love python / you guys :)

2009-11-16 Thread Dave Angel
(Multiple people on this thread have been quoting earlier people without keeping the attribution lines (e.g. yyy wrote: ) so I'm not sure who said what any more. I recognize my own words, of course, but for anybody else, your guess is better than mine) Stephen Nelson-Smith wrote:

Re: [Tutor] pyce, scripts complete too fast

2009-11-17 Thread Dave Angel
rick wrote: Perhaps the wrong list, but I'll ask anyway. So I'm in the middle of starting, yet again, to learn some programming. I have 2.6.4 and 3.1 installed on the desktop (Ubuntu 9.10), 2.6.4 installed on the netbook (UNR 9.10). I was thinking to be ultra portable, I'd put python on t

Re: [Tutor] Introduction - log exercise

2009-11-17 Thread Dave Angel
Antonio de la Fuente wrote: Hi everybody, This is my first post here. I have started learning python and I am new to programing, just some bash scripting, no much. Thank you for the kind support and help that you provide in this list. This is my problem: I've got a log file that is filling up

Re: [Tutor] Introduction - log exercise

2009-11-17 Thread Dave Angel
Antonio de la Fuente wrote: * Dave Angel [2009-11-17 16:30:43 -0500]: for line in fileIn: if line.isspace

Re: [Tutor] TypeError: Need Help

2009-11-19 Thread Dave Angel
Ali Sina wrote: I have Python 3.0 and I'm trying to learn from a pdf document. I followed its instructions >>but I've encountered a problem in its Pickling chapter. This is the code I've written: import pickle, shelve print('Pickling list.') variety=['sweet','hot','dill'] shape=['wh

Re: [Tutor] Readable date arithmetic

2009-11-19 Thread Dave Angel
Kent Johnson wrote: On Thu, Nov 19, 2009 at 1:14 AM, Stephen Nelson-Smith wrote: I have the following method: def get_log_dates(the_date_we_want_data_for): t =ime.strptime(the_date_we_want_data_for, '%Y%m%d') t2 =atetime.datetime(*t[:-2]) Use datetime.datetime.strptime() to save a

Re: [Tutor] Querying a packages modules?

2009-11-20 Thread Dave Angel
Eric Pavey wrote: On Fri, Nov 20, 2009 at 4:09 AM, Kent Johnson wrote: On Thu, Nov 19, 2009 at 9:31 PM, Eric Pavey wrote: Say I have this package layout \myPackage __init__.py moduleA.py moduleB.py Is there a way (and I'm sure there is...) to query, for a given package level, whic

Re: [Tutor] Querying a packages modules?

2009-11-20 Thread Dave Angel
Eric Pavey wrote: On Fri, Nov 20, 2009 at 11:14 AM, Eric Pavey wrote: On Fri, Nov 20, 2009 at 10:58 AM, Eric Pavey wrote: On Fri, Nov 20, 2009 at 10:40 AM, Dave Angel wrote: lol, in usual fashion, after I hack through it, while in the docs, I find the 'fancy'

Re: [Tutor] About classes and databases

2009-11-22 Thread Dave Angel
Michele Alzetta wrote: Hallo all! Long time since I last dabbled in python :-( I was thinking of a possible solution to a problem I have: I could make a Class which contains, amongst other things, a couple of datetime.datetime objects. The class also will have to contain an element taken from a

Re: [Tutor] Class understanding

2009-11-24 Thread Dave Angel
Che M wrote: Date: Tue, 24 Nov 2009 10:27:05 -0600 From: jammer10...@gmail.com To: tutor@python.org Subject: [Tutor] Class understanding Hi all... Have been attempting to understand classes... Been getting along without them for a while now and feel it's time to jump in What I want t

Re: [Tutor] the art of testing

2009-11-24 Thread Dave Angel
Serdar Tumgoren wrote: Lie and Kent, Thanks for the quick replies. I've started writing some "requirements", and combined with your advice, am starting to feel a bit more confident on how to approach this project. Below is an excerpt of my requirements -- basically what I've learned from revie

Re: [Tutor] the art of testing

2009-11-24 Thread Dave Angel
Serdar Tumgoren wrote: That's a good start. You're missing one requirement that I think needs to be explicit. Presumably you're requiring that the XML be well-formed. This refers to things like matching and nodes, and proper use of quotes and escaping within strings. Most DOM parsers won

Re: [Tutor] Nested loop of I/O tasks

2009-11-24 Thread Dave Angel
Bo Li wrote: Dear Python I am new to Python and having questions about its usage. Currently I have to read two .csv files INCT and INMRI which are similar to this INCT NONAME 121.57 34.71 14.81 1.35 0 0 1 Cella 129.25 100.31 27.25 1.35 1 1 1 Chiasm 130.3 98.49 26.05 1.35 1 1 1 FMagnu

Re: [Tutor] python time

2009-11-26 Thread Dave Angel
spir wrote: Hello, How does python get the time in microseconds? (In other words, how would I get it if python (like some other languages) would provide time in whole seconds only?) Thank you, Denis la vita e estrany http://spir.wikidot.com/ You need to

Re: [Tutor] Iterating over two sequences in "parallel"

2009-11-28 Thread Dave Angel
Jose Amoreira wrote: Hi! I want to process corresponding elements of two lists, sequentially. Call the lists list1 and list2, and assume they have equal lengths. I can do something like for index in range(len(list1)): process(list1[index], list2[index]) But I find it somehow rather ugly,

Re: [Tutor] Equivalent exception of os.path.exists()

2009-11-30 Thread Dave Angel
spir wrote: biboy mendz dixit: http://pastebin.ca/1693849 This is end-of-chapter3 exercise of the book Core Python Programming. I'm reading/searching in the book and other materials but is unsuccessful. There are at least 50 exceptions listed but I can't find anything close. I comment

Re: [Tutor] python closures

2009-11-30 Thread Dave Angel
Alan Gauld wrote: "spir" wrote I did wonder if you would need n=n but I didn't think you would need x=x. Its an interesting example and I confess I don't fully understand how Python's naming/reference rules are working here. to let the inner func g0 "remember" outer values. Why is this id

Re: [Tutor] x is a global variable

2009-11-30 Thread Dave Angel
spir wrote: Hello Eike! Eike Welk dixit: Well, this is certainly not specific to closures. i = 0 def f(): i = i+1 print i f() ==> UnboundLocalError Imo, in this case, "i = i+1" is a kind of "paradoxal injonction" (lol! not sure of the exact idiom in english). You tell python both t

Re: [Tutor] [Errno 9] Bad file descriptor

2009-12-01 Thread Dave Angel
Khalid Al-Ghamdi wrote: Hi everybody, I'm running python 2.6.1 on vista and I'm trying to use the csv module to write to a csv file and get the average of some numbers, but I keep getting the following error: Traceback (most recent call last): File "C:\Python31\MyCSVProjectFinal.py", line 83,

Re: [Tutor] working with bit arrays

2009-12-02 Thread Dave Angel
Robert Berman wrote: Emille, I do think he meant bit 20 to 32 rather than 20 to 40. Unless, of course, he's dealing with a 64 bit word. You posted out of order (top--osted). So I am forced to put my response elsewhere. I am delighted with all the help I have received on this topic and I a

Re: [Tutor] Dictionary Comprehensions

2009-12-04 Thread Dave Angel
Khalid Al-Ghamdi wrote: Hi everyone! I'm using python 3.1 and I want to to know why is it when I enter the following in a dictionary comprehension: dc={y:x for y in list("khalid") for x in range(6)} I get the following: {'a': 5, 'd': 5, 'i': 5, 'h': 5, 'k': 5, 'l': 5} instead of

Re: [Tutor] saving output data in a file

2009-12-04 Thread Dave Kuhlman
t 'something else' redir.close() sys.stdout = save_stdout print 'finished' test() # A few notes: - Be sure to close or flush the file. - The chunks passed to your write method may not be whole lines. - Dave >

Re: [Tutor] saving output data in a file

2009-12-06 Thread Dave Angel
spir wrote: class Out(file): def __init__(self, filename, toconsole=True, numberlines=True): file.__init__(self, filename, 'r') print self # debug output to console self.toconsole = toconsole # line numberi

Re: [Tutor] loops

2009-12-08 Thread Dave Angel
Richard Hultgren wrote: a = 0 b = 1 count = 0 max_count = 20 while count < max_count: count = count + 1 # we need to keep track of a since we change it old_a = a# especially here old_b = b a = old_b b = old_a + old_b # Notice that the , at the end of a

Re: [Tutor] File renaming using os.rename problem

2009-12-08 Thread Dave Angel
spir wrote: Roy Hinkelman dixit: I can't find anything on this error I am getting when renaming some files. I'm pulling info from a csv file and parsing it to build new file names. Any pointers appreciated Roy My code: # RENAME FILES using META file - new name = [place]_[state]_[sku].tif

Re: [Tutor] duplication in unit tests

2009-12-08 Thread Dave Angel
Serdar Tumgoren wrote: Hi Kent and Lie, First, thanks to you both for the help. I reworked the tests and then the main code according to your suggestions (I really was muddling these TDD concepts!). The reworked code and tests are below. In the tests, I hard-coded the source data and the expect

Re: [Tutor] Sound problems

2009-12-10 Thread Dave Angel
Tim Goddard wrote: I'm still learning, and this may be better served on a pygame mailing list but I thought I'd try here first. I'm following the python programming for absolute beginners which uses livewires and pygame to do some simple games. My difficulty comes from not using the module vers

Re: [Tutor] typerror

2009-12-11 Thread Dave Angel
Roshan S wrote: class Student: print"We have a new student " def __init__(self,name='',credit=0,grade=0,quality=0): self.name=name self.credit=credit self.grade=grade self.quality=quality def inputstudent(self): self.name=raw_input("Enter stu

Re: [Tutor] Need a better name for this function

2009-12-15 Thread Dave Angel
Richard D. Moores wrote: def float_to_exact_number_stored_in_computer(f): """ Given a float, return the exact number stored in computer. See http://docs.python.org/3.1/tutorial/floatingpoint.html#representation-error """ from decimal import Decimal return Decimal.from_float(f)

Re: [Tutor] Need a better name for this function

2009-12-15 Thread Dave Angel
Richard D. Moores wrote: On Tue, Dec 15, 2009 at 15:05, Dave Angel wrote: Richard D. Moores wrote: If I keep the function, renamed to Allan's suggested float2Decimal(), then that's all I'll have to remember. But I see yours and Hugo's point. Just remember, if th

Re: [Tutor] Need a better name for this function

2009-12-16 Thread Dave Angel
#x27;s precisely what float2Decimal() returns for 0.1 . The docs are right. The function will give you the exact value of any floating point number stored in memory. OK! I think what Dave is trying to say is that if you want to store the exact value 0.1 on your computer, this funct

Re: [Tutor] faster substring replacement

2009-12-16 Thread Dave Angel
R. Alan Monroe wrote: I'm wondering whether text.replace has to shove oodles of text to the right in memory when you replace a shorter word with a longer word. Someone else on the list may know. Alan Since a string is immutable, replace() has to copy the string. So it doesn't need to

Re: [Tutor] Need a better name for this function

2009-12-16 Thread Dave Angel
Richard D. Moores wrote: On Wed, Dec 16, 2009 at 14:48, Richard D. Moores wrote: I just realized that my question was absurd, in that given real numbers n and x there is no x such that both x < n and x is greater than all other numbers less than n. So after inserting "(in 14 hex digits)" at 2

Re: [Tutor] Need a better name for this function

2009-12-17 Thread Dave Angel
Richard D. Moores wrote: On Wed, Dec 16, 2009 at 20:23, Dave Angel wrote: Richard D. Moores wrote: There are conceivably better ways to get at the mantissa of the fp number, but you can simply parse the hex digits as I did manually, and add one and subtract one from the given

Re: [Tutor] Please take a look at this function

2009-12-17 Thread Dave Angel
Richard D. Moores wrote: def prestrings2list(a_str): word = "" list_of_strings = [] length_of_a_string = len(a_str) for i, char in enumerate(a_str): if i == length_of_a_string - 1: word += char word = word.rstrip() list_of_strings.append

Re: [Tutor] Field/Variable References

2009-12-18 Thread Dave Angel
John Filben wrote: Can someone please let me know how to read a file one record at a time (just say fixed block for now - see small example below) and assign columns to fields. Then reference the field names with if-then-else logic. Sample Fixed Block File: John98762 John82634 John11234 Tha

Re: [Tutor] print IP address range to stdout

2009-12-22 Thread Dave Angel
MK wrote: Hi there, i have some logical problem. I dont get it done to write my for loops in that way that the ip address range which is given as arguments are correct processed. Meaning that only the ips are printed which the user defines as argument. I tried to make an if statement to stop a

Re: [Tutor] print IP address range to stdout

2009-12-22 Thread Dave Angel
#x27; for exp in [3,2,1,0]: octet = octet + str(intip / (256 ** exp)) + "." intip = intip % ( 256 ** exp) return (octet.rstrip(".")) Am Dienstag, den 22.12.2009, 06:32 -0500 schrieb Dave Angel:

Re: [Tutor] try and except

2009-12-31 Thread Dave Angel
spir wrote: Lie Ryan dixit: class Error(Exception): def __init__(self, value): self.value = value def printer(self, value): print self.value You can also use __str__ instead of printer. This will give a standard output form for your error automatically use

Re: [Tutor] using re to match text and extract info

2009-12-31 Thread Dave Angel
Norman Khine wrote: hello, import re line = "ALSACE 67000 Strasbourg 24 rue de la Division Leclerc 03 88 23 05 66 strasbo...@artisansdumonde.org" m = re.search('[\w\-][\w\-\...@[\w\-][\w\-\.]+[a-za-z]{1,4}', line) emailAddress .search(r"(\d+)", line) phoneNumber = re.compile(r'(\d{2}) (\d{2

Re: [Tutor] Finding a repeating sequence of digits

2010-01-02 Thread Dave Angel
Robert Berman wrote: Hi, I am trying to build an algorithm or methodology which will let me tell if a decimal has a repeating sequence of digits and if it does have that attribute, what is the sequence of digits. For example, 1/3.0 = 0.3..By eyeballing we know it has a repeating sequence

Re: [Tutor] How to open the closed file again?

2010-01-05 Thread Dave Angel
Alan Gauld wrote: "朱淳" wrote fileList = [] def openFiles(): for i in range(0,2): fname = "file%s"%i f = open(fname,"a") fileList.append(f) def closeFiles(): for f in fileList: f.close() if __name__=="__main__": openFiles() print "fileList closeFiles() print fileList openFiles() print fileL

Re: [Tutor] How to open the closed file again?

2010-01-05 Thread Dave Angel
Andre Engels wrote: On Tue, Jan 5, 2010 at 1:46 PM, 朱淳 wrote: I've token a dictionary to save filenames, and write it into "constant.py". And I think it's a good method to create a class as Andre wrote. Thank you all! By the way, if I close a open file object, will the closed file object st

Re: [Tutor] (no subject)

2010-01-09 Thread Dave Angel
sudhir prasad wrote: hi, iam a beginner. sample_file = file("/home/ee08m082/Desktop/python/123.txt","w") sample_file.write("About Pythons\n") in the above two line code,123.txt is being created but "About Pythons" is not being written in the file. my OS is redhat linux and python version is 2

[Tutor] Problems with class, no output

2004-12-19 Thread Dave S
t. I just know you guys are going to tell me I have missed a () or . somewhere Any help gratefully appreciated Dave #!/usr/bin/env python # -*- coding: iso8859_1 -*- """ arch_data.py 1.0 This is the read archive data script """ from os import listdir from cPickle import

Re: [Tutor] Problems with class, no output

2004-12-19 Thread Dave S
Dave S wrote: Hello again :-) , This script is very much a work in progress, and I think only the second time I have tried classes. What I expected it to do was to at least print 'hi there' so I know its alive, then dump some status info to my log program. It does zip, executes

Re: [Tutor] Problems with class, no output

2004-12-19 Thread Dave S
Kent Johnson wrote: Dave, For some reason the indentation is very strange in this code. I think it must have something to do with how you posted it (or my mailer is messing it up?), as it would be a syntax error at runtime. If you can have more consistent indentation in your posts it will make

[Tutor] Marry Xmas + httplib.py problem :)

2004-12-24 Thread Dave S
e since my app has downloaded approx 60 web pages from this location today just before the exception occured ?, or maybe something else ? Should I check for this exception when I ... new_data=html_strip(load_webpage()) & if it occures, try again ? Any comments gratefully recieved. Cheers (H

[Tutor] simple list query

2005-01-02 Thread Dave S
e is a better way ? Any suggestions Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] simple list query

2005-01-02 Thread Dave S
Patrick Hall wrote: Hi Dave, I have a list consisting of about 250 items, I need to know if a particular item is in the list. I know this is better suited to a dictionary but thats not the way it ended up ;-) I could do a for loop to scan the list & compare each one, but I ha

[Tutor] Am I storeing up problems ?

2005-01-02 Thread Dave S
ll this OK, it works and quick as well, but I am concerned I may be leaving garbage in the Python PVM since I am shrugging off old 'self.old_data's which may be mounting up ? Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Am I storeing up problems ?

2005-01-03 Thread Dave S
Danny Yoo wrote: On Sun, 2 Jan 2005, Dave S wrote: My matrix 'self.data' consists of a list of 110 items, each item is a dictionary of 250 keys, each key holds two lists, one of four items, one of 12 items. Hi Dave, Hmmm... what kind of data is being copied here? Python's

Re: [Tutor] Am I storeing up problems ?

2005-01-03 Thread Dave S
his OK, it works and quick as well, but I am concerned I may be leaving garbage in the Python PVM since I am shrugging off old 'self.old_data's which may be mounting up ? But apparently this is ok (as he cancelles order gor 1GB RAM ;-) ) Dave __

[Tutor] 2d list matrix 7 x 75 problem

2005-03-06 Thread Dave S
', '', '', ''], ['', '', '', '', '']] except its dimensions need to be 7 x 75. I thought I had it sorted with map2 = [ [''] *7 ] *75 until the coding screwed up & I realised I had 75 references to th

Re: [Tutor] 2d list matrix 7 x 75 problem

2005-03-06 Thread Dave S
Jeff Shannon wrote: On Sun, 06 Mar 2005 09:49:43 +, Dave S <[EMAIL PROTECTED]> wrote: I need to generate a list 2d matrix of the kind ... [['', '', '', '', ''], ['', '', '', '', ''], [&

[Tutor] Acessing files in Windows 2000

2005-03-08 Thread Dave S
gling. I have tried just about every combination of \ and / and \\ and // but to no avail. I need something like ... C:\My Documents\memo.txt Can anyone advise me ? Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Acessing files in Windows 2000

2005-03-08 Thread Dave S
nd Settings\Administrator\Desktop\palm.py", line 54, in palm_conv memo = open(memo_file, 'r') IOError: [Errno 2] No such file or directory: 'c:\\my documents\\memo.txt' >>> If I try c:\\ or c:\ it always comes out as c:\\... and fails Dave

Re: [Tutor] Acessing files in Windows 2000

2005-03-09 Thread Dave S
let's help Dave with his problem. The os.path module contains a function called expanduser() that returns the home directory of a given user. http://www.python.org/doc/lib/module-os.path.html#l2h-1720 I believe this should reliably return a path that looks something like '\\Do

Re: [Tutor] Acessing files in Windows 2000

2005-03-09 Thread Dave S
re. Um --- So you have a file 'C:\Documents and Settings\Administrator\My Documents\memo.txt'... But you are attempting to open the file 'C:\Documents and Settings\Administrator\memo.txt'. There is a difference there! mmm ... I kind of see what you mean. Does anyone hav

[Tutor] Windows user variable ?

2005-06-26 Thread Dave S
play strips anything after the '.', found the problem via dos :) Anyhow - When logged into 2000 as an administrator or user is there a system variable that I can read to let the script know who I am logged in as ? Dave ___ Tutor maillist - Tutor@p

Re: [Tutor] Windows user variable ?

2005-06-27 Thread Dave S
Thanks for your help guys Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] OT python Licences

2005-07-12 Thread Dave S
hand it over ? Secondly it would have to run in Windows, The results could pop up on a DOS window. However I was looking at QT until I read the Windows license. Are there any widget libraries that would allow me to program for windows commercially without any license or fees ? Thanks in advance Dave

Re: [Tutor] OT python Licences

2005-07-12 Thread Dave S
Many thanks for all your input, you have been great. At the moment Tkinter is a favorite, I have started reading the documentation and it seems fairly straightforward + can do what I need. Many thanks once again :-) Dave ___ Tutor maillist - Tutor

[Tutor] Tkinter query?

2005-07-13 Thread Dave S
independant_win = Toplevel(root) But I do not understand where Frame fits in to this ... ie from Tkinter import * class Hello(Frame): def __init__(self, parent=None): Frame.__init__(self, parent) self.pack() Why not just use 'class Hello(root)' ? Or have I m

Re: [Tutor] Tkinter query?

2005-07-13 Thread Dave S
Dave S wrote: >Hi all, > >Im on the Tkinter GUI learning curve :-) . Its going quite well - im >reading O'reilly 'programming python' but I am unclear on the following > >I understand the standard form ie ... > >root = Tk() >test = button(root, text = ..

Re: [Tutor] Tkinter query?

2005-07-13 Thread Dave S
Kent Johnson wrote: >Dave S wrote: > > >>>But I do not understand where Frame fits in to this ... ie >>> >>> >>> >>>from Tkinter import * >> >> >> >>>class Hello(Frame): >>> >

Re: [Tutor] Tkinter query?

2005-07-14 Thread Dave S
.pack(expand=True) > > tk.mainloop() > Thank you, that has clarified a few points but raised a query. tk.geometry('400x400') does not appear to have any effect on its size when the window is drawn, the window is always the same size and short of maximizing it to full screen it is not adjustable. Just a minor query but interesting Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] trying to figure out what this means

2007-05-07 Thread Dave C
when you are doing print these two characters keep showing up in this book "%s" % What do they do? here is example of complete command. print "%s" % last_names[-2] Thank you, Dave ___ Tutor maillist - Tutor@python.org ht

Re: [Tutor] Parsing text file

2007-05-14 Thread Dave Kuhlman
to have in your tool bag. And, like I said above: It's fun. Besides, if your problem becomes more complex, and, for example, the input is not quite so line oriented, you will need a more powerful approach. Wikipedia has a better explanation than mine plus an example and links: http://en.wikipedi

Re: [Tutor] Fastest way to iterate through a file

2007-06-26 Thread Dave Kuhlman
speed is important, then you might try a solution that uses a regular expression in place of for id in idList: if id in line: A regular expression of the form "(id1|id2|id2)", which you could construct programmatically, might work for your problem: import re s1 =

Re: [Tutor] Importing and creation on the fly

2007-06-26 Thread Dave Kuhlman
gave me > an error when I did the eval(actionStmt). Could anybody shed some light on > this? Thanks in advance. For the task of importing, look at the "imp" module: http://docs.python.org/lib/module-imp.html Also, the "inspect" module may be of help: http://d

Re: [Tutor] backslashes

2007-07-08 Thread Dave Kuhlman
en(s1) Out[3]: 9 In [4]: s1.replace('\\', '') Out[4]: 'abcdefg' Notice the length of the string (before removing the backslashes). Each apparently double backslash actually has a length of 1. Dave -- Dave Kuhlman http://www.rexx.com/~dkuhlman ___

<    1   2   3   4   5   6   7   8   9   10   >