Re: [Tutor] passing dictionaries through a file

2015-03-17 Thread David Heiser
On 3/16/2015 5:04 PM, Alan Gauld wrote: On 16/03/15 20:39, Doug Basberg wrote: I would like to pass the contents of a dictionary from one program to another through a file. So, what is the elegant way to pass a dictionary by file? The elegant way may be not to use a file. A Python diction

Re: [Tutor] file exists question

2015-03-09 Thread David Heiser
On 3/9/2015 9:50 AM, Alan Gauld wrote: Somebody posted a question asking how to fond out if a file exists. The message was in the queue and I thought I'd approved it but it hasn't shown up yet. Sorry to the OP if I've messed up. The answer is that you use the os.path.exists() function. It take

[Tutor] Alan's book - was "Learning python scripts for practical linux activities."

2015-01-15 Thread David Heiser
Thanks for the Shameless Plug, Alan. I went to Amazon, scanned through your book, and learned some things about "sets" that will help me in my job. Bought the Kindle version. Great stuff. On 1/15/2015 8:53 AM, Alan Gauld wrote: On 15/01/15 14:07, dw wrote: I would like to find a source,

Re: [Tutor] Ideas for Child's Project

2015-01-06 Thread David Heiser
Twelve years ago, I started with "The Quick Python Book". Harms and McDonald. Manning Pub. I learned a lot in a hurry. I still use it for reference once in a while to refresh my memory. On 1/6/2015 1:46 PM, Stephen Nelson-Smith wrote: Hello, My son is interested in programming, and has da

Re: [Tutor] Iterating through two lists at the same time withmanipulation..

2007-06-28 Thread David Heiser
A dictionary would work well here. Read each element of the lists into the dictionary using the integer as the key with a list of strings as the values. {1: ['A', 'AA'], 2: ['B'], 3: ['C', 'CC'], 4: ['D', 'DD']} Then output the contents in the required format. This may take more lines of code t

Re: [Tutor] Hi,every one

2007-06-22 Thread David Heiser
I seldom hear anyone mention "The Quick Python Book" by Daryl Harms and Kenneth McDonald (Manning). It was the book I found most useful when I started programming Python. I still keep it nearby and refer to it occasionally as a familiar memory refresher, even though I have been writing Python cod

Re: [Tutor] iterating over a sequence question..

2007-06-17 Thread David Heiser
I love this [Tutor] list. There are always new tricks that change the way I write code. And it makes me like Python more every day. I keep a script file with "notes" on the things I learn here and I refer to these notes frequently. Here are the notes I made for this thread: """ iterate/map/modu

Re: [Tutor] Engarde program was: i++

2007-06-07 Thread David Heiser
Very nice trick. Thanks. P.S. You can still use: s = raw_input(question).lower()[:1] if s == ...: -Original Message- From: Danny Yoo [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 06, 2007 5:53 PM To: David Heiser Cc: tutor@python.org Subject: Re: [Tutor] Engarde

Re: [Tutor] Engarde program was: i++

2007-06-07 Thread David Heiser
What if the user enters "maybe". -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alan Gauld Sent: Thursday, June 07, 2007 1:45 AM To: tutor@python.org Subject: Re: [Tutor] Engarde program was: i++ "David Heiser" <[EMAIL PROT

Re: [Tutor] Engarde program was: i++

2007-06-06 Thread David Heiser
or.. def is_yes(question): while True: try: s = raw_input(question).lower()[0] if s == 'y': return True elif s == 'n': return False except: pass ## This traps the condition where a user

Re: [Tutor] tokenizing a simple string with split()

2007-03-31 Thread David Heiser
Or you can try something like: x = r"C:\My\Doc\;D:\backup" x = x.replace("\\", ";") x = x.split(";") -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kent Johnson Sent: Saturday, March 31, 2007 9:42 PM To: Andrei Petre Cc: tutor@python.org Subject: Re: [

Re: [Tutor] I am terribly confused about "generators" and "iterators".. Help me

2006-10-27 Thread David Heiser
May I invite EVERYONE to NOT introduce political or religious elements into these discussions. It has no place here and can destroy this excellent discussion group. I've seen it happen. PLEASE take it elsewhere. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Beh

Re: [Tutor] Capture telnet output to a file?

2006-10-16 Thread David Heiser
Here is a snippet of code that may work for you: #--- import telnetlib HOST = "myServer" Username = "bob" Password = "fido" LoginList = ['=login:', '%s=password:' % (Username), '%s=$' % (Password)] ## Like an Expect script Terminator = "$" print "CONNECTING:" T

[Tutor] Reading escaped characters from a file

2006-10-14 Thread David Heiser
Title: Message   I have code that uses variables to hold escaped characters like "\n" or "\03". As long as the assignment is done within the code, like self.crChar = "\n", there is no problem. But When I try to read the same character string from a text file and assign it, the string is seen

Re: [Tutor] Better way to substitute text?

2006-09-30 Thread David Heiser
You can make it simpler by not splitting the input file into lines. Treat it as a single string. in_put = open('test.html', 'r').read() replace_words = ['TWY', 'RWY', 'WIP'] for replace_word in replace_words: in_put = in_put.replace(replace_word, "" + replace_word + "")

Re: [Tutor] dictionary manipulation

2006-07-26 Thread David Heiser
Title: Message   Chris,   This looks similar to what I do for my job. I would be happy to help you, if I can.   My first question is, how would you like the output to look? Can you manually create a model of the email text you want to send?   My second question is, can you create the email

Re: [Tutor] Escape sequences

2006-06-22 Thread David Heiser
That worked just dandy. Thanks. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kent Johnson Sent: Thursday, June 22, 2006 1:03 PM Cc: tutor@python.org Subject: Re: [Tutor] Escape sequences David Heiser wrote: > I have code that assigns esc

[Tutor] Escape sequences

2006-06-22 Thread David Heiser
x27;resetString']". Simple ASCII strings work fine, but the escape sequences don't work and the code fails. "print self.resetString" returns "\\03", instead of a nonprintable character. Any ideas? David Heiser ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Searching across .Py files for a particular string/character

2006-03-30 Thread David Heiser
Here's a simple Python script that will do it. It's not very sophisticated, but it's easy to modify for special cases. import os, string def Find(TargetString, DIR, Names): for Name in Names: if Name != "Search.py": try: TargetFile = DIR + "/" + Name

Re: [Tutor] scaling values

2006-03-14 Thread David Heiser
Is this what you're asking for? # Scaler.py # def scale(OldList, NewMin, NewMax): NewRange = float(NewMax - NewMin) OldMin = min(x) OldMax = max(x) OldRange = float(OldMax - OldMin) ScaleFactor = NewRange / OldRange print '\nEquasion: NewValue = ((OldValue - ' + str(Old

Re: [Tutor] Analysing genetic code (DNA) using python

2006-03-06 Thread David Heiser
Here's one approach to the problem (using bogus codon values). -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of sjw28 Sent: Monday, March 06, 2006 8:37 AM To: tutor@python.org Subject: [Tutor] Analysing genetic code (DNA) using python I have many note

Re: [Tutor] Print list vs telnetlib.telnet.write differences

2006-03-02 Thread David Heiser
I believe you can submit the new config content as a blob where blob = string.join(lines). It looks like your "switch" uses IOS, not CatOS, so make sure you send "config t" first. And I would strip out the \r's. Then maybe: tn.write("\03") # Assures the device

Re: [Tutor] Telnet to cisco device

2006-02-28 Thread David Heiser
Title: Message   The following works with the Cisco switch that I have available. Cisco 4006 with CatOS 6.2. It may not work with your model/OS or your switch may be configured differently. For instance, the default prompt terminates with "(enable)" so I used "tn.read_until(')')" instead of