Re: [Tutor] os.popen doesn't give up
--- Ben Vinger <[EMAIL PROTECTED]> wrote: > --- Bob Gailer <[EMAIL PROTECTED]> wrote: > > Solutions: > > 2 - l = os.popen(r'snmpget -Os -c ' + > SNMPcommunity > > + ' -v2c -r 3 ' + IP + > > ' ' + counter, 'r').read() Puts snmpget's output > in > > l. Sorry, now I have doubts again. Originally, I had: I = os.popen(r'snmpget -Os -c ' + SNMPcommunity + ' -v 2c -r 3 ' + IP + ' ' + counter, 'r') bytes = string.split(I.read(), None)[3] With Bob's suggestion, I have: I = os.popen(r'snmpget -Os -c ' + SNMPcommunity + ' -v 2c -r 3 ' + IP + ' ' + counter, 'r').read() bytes = string.split(I, None)[3] But is this really different? I can add I.close() as you suggested, maybe that will do the trick. Thanks Ben ___ Moving house? Beach bar in Thailand? New Wardrobe? Win £10k with Yahoo! Mail to make your dream a reality. Get Yahoo! Mail www.yahoo.co.uk/10k ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor
how to run a programm after you have typed in the commands (was Re: [Tutor] help (fwd))
It sounds like you've been using the Python interactive prompt such as IDLE. You can type the same Python statements you've used there into a text editor or Python IDE and save it. Let's say you have created a Python program/script called hello.py in a text editor and saved it. You can now open a command prompt (Windows) or console (linux) in the directory where your program is saved. Then type: python hello.py If you are using Windows and this does not work, it will be because Python is not in your system path. Good luck Ben --- Danny Yoo <[EMAIL PROTECTED]> wrote: > > > -- Forwarded message -- > Date: Wed, 13 Apr 2005 17:12:55 +0200 > From: Feziwe Mpondo <[EMAIL PROTECTED]> > To: [EMAIL PROTECTED] > Subject: help > > how to run a programm after you have typed in the > commands > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > Send instant messages to your online friends http://uk.messenger.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
Or like this: for x in range (0,256): print ord(chr(x)), ': ', chr(x) (you could just print x, instead of ord(chr(x)), but then you would not be using ord) Ben --- Pujo Aji <[EMAIL PROTECTED]> wrote: > Actually you can do the same way: > > # Convert intAscii to charAscii > S = [chr(x) for x in range(0,256)] > for x in S: print x > > #Convert charAscii to intAscii > AsciiInt = [ord(x) for x in S] > for x in AsciiInt: print x > > Best Regards, > pujo > > On 5/26/05, John Carmona <[EMAIL PROTECTED]> > wrote: > > With the help of Pujo Aji I have written this > little script that print every > > single ASCII code>> > > > > S = [chr(x) for x in range (0,256)] > > for x in S: > > print x, > > > > The next step is to use the built-in functin ord() > in order to convert each > > character to an ASCII integer. I have had a look > at the ord() function but > > it says that it only take one argument i.e. > ord('a'). How could I execute to > > convert each character into an ASCII integer? > > > > Thanks in advance > > JC > > > > > > ___ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Can't remember an address in your address book? Enter the first few letters and Address AutoComplete will automatically finish it. Get Yahoo! Mail http://uk.mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject). Ord and Chr query
--- John Carmona <[EMAIL PROTECTED]> wrote: > Ben I could not get your script working indentation? ___ Can't remember an address in your address book? Enter the first few letters and Address AutoComplete will automatically finish it. Get Yahoo! Mail http://uk.mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] replaying
Mailman can be set up to reply to the forum, but people on this list prefer to live with pain! --- geon <[EMAIL PROTECTED]> wrote: > Hi, > > Seems to me as very unuseful thing in this phorum, > when I choose Replay > to any message, the field "to whom or Receiver" is > all the time not > tutor@python.org but the original sender! Why? I can > not understand that? > > It sould be prefferably posted back to mailing list > IMHO. > > > -- > geon > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ How much free photo storage do you get? Store your holiday snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hy, I'm a n00b to Python, have some questions
--- Alex Nedelcu <[EMAIL PROTECTED]> wrote: > 4. What's the hottest web framework right now that > does not require an > application server (meaning that it runs on fastcgi) Take a look at Myghty - it seems pretty good - it is a Python rewrite of Perl::Mason (which Amazon.com is based on). You can run it through mod_python which I believe performs better than fastcgi. ___ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] PYTHON????
The Python interpreter already contain the code for multiplication, so you don't need to write it. You can just use it: x = raw_input('give the first number') y = raw_input('give the second number') print x, ' times ', y, ' is', int(x) * int( y) Or in the interactive interpreter you can just: >>> 2 * 4 8 Good Luck! --- [EMAIL PROTECTED] wrote: > Dear Python, > How does a calculator multiply? I want to create a > computer software that can multiply. How do I > program the computer to multiply? > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] hey i need some help here
It is almost certain that you are using MS Windows, and that Python is not in you "system path". If so, here's what to do: Add the top-level Python directory to your Windows "PATH". On Windows NT this is done with Control Panel/System/Environment. On Windows 2000 and Windows XP it is done with Control Panel/System/Advanced/Environment Variables. Edit the PATH environment variable in the System settings to add C:\Python22 or C:\Program Files\Python22 (or wherever you put Python) (taken from http://cars9.uchicago.edu/software/python/) Ben --- Matt Warren <[EMAIL PROTECTED]> wrote: > I just started attempting to program and thought i > would try python as my > first tool. However following the beginners guide on > their page it says to > insert python as a command and that it should come > up with the program > information. When i insert python it says it is not > recognizable as an > internal or external command. can somebody help me? > ___ How much free photo storage do you get? Store your holiday snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Website monitoring program.
Below is a program I found at http://starship.python.net/crew/neale/ (though it does not seem to be there anymore.) It uses a seperate file for the URLs --- Adisegna <[EMAIL PROTECTED]> wrote: > My question is how to use a loop to go through a > tuple of URLs. Please feel > free to suggest an easier way to do the same thing. #!/usr/bin/env python """watch.py -- Web site change notification tool Author: Neale Pickett <[EMAIL PROTECTED]> Time-stamp: <2003-01-24 13:52:13 neale> This is something you can run from a cron job to notify you of changes to a web site. You just set up a ~/.watchrc file, and run watcher.py from cron. It mails you when a page has changed. I use this to check for new software releases on sites that just change web pages; my wife uses it to check pages for classes she's in. You'll want a ~/.watchrc that looks something like this: to: [EMAIL PROTECTED] http://www.example.com/path/to/some/page.html The 'to:' line tells watch.py where to send change notification email. You can also specify 'from:' for an address the message should come from (defaults to whatever to: is), and 'host:' for what SMTP server to send the message through (defaults to localhost). When watch.py checks a URL for the first time, it will send you a message (so you know it's working) and write some funny characters after the URL in the .watchrc file. This is normal--watch.py uses these characters to remember what the page looked like the last time it checked. """ import os.path import urllib2 as urllib import sha import smtplib rc = '~/.watchrc' host = 'localhost' fromaddr = None toaddr = None def hash(data): return sha.new(data).hexdigest() def notify(url): msg = """From: URL Watcher <%(from)s> To: %(to)s Subject: %(url)s changed %(url)s has changed! """ % {'from': fromaddr, 'to': toaddr, 'url': url} s = smtplib.SMTP(host) s.sendmail(fromaddr, toaddr, msg) s.quit() fn = os.path.expanduser(rc) f = open(fn) outlines = [] for line in f.xreadlines(): if line[0] == '#': continue line = line.strip() if not line: continue splits = line.split(' ', 1) url = splits[0] if url == 'from:': fromaddr = splits[1] elif url == 'to:': toaddr = splits[1] if not fromaddr: fromaddr = toaddr elif url == 'host:': host = splits[1] else: if (not fromaddr) or (not toaddr): raise ValueError("must set to: before any urls") page = urllib.urlopen(url).read() ph = hash(page) try: h = splits[1] except IndexError: h = None if h != ph: notify(url) line = '%s %s' % (url, ph) outlines.append(line) f.close() f = open(fn, 'w') f.write('\n'.join(outlines) + '\n') f.close() ___ Yahoo! Model Search 2005 - Find the next catwalk superstars - http://uk.news.yahoo.com/hot/model-search/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] extra characters in XML
Hello all I want to do the following in an XML file: XFile = open(XmlFile,'r') for line in XFile.readlines(): if line.find('') > 0: print line However, it does not work due to extra characters that appear in the XML file. For example if I use the previous code without the if condition, on a console it looks like: < e n d _ t i m e > And if you output that to a text file and open that in a text editor, the text editor shows a square instead of a space in between every character. What is going on? Thanks Ben ___ Yahoo! Photos NEW, now offering a quality print service from just 8p a photo http://uk.photos.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] extra characters in XML
Found the following (which solved the problem, though not on the console) at http://www.jorendorff.com/articles/unicode/python.html import codecs # Open a UTF-8 file in read mode infile = codecs.open("infile.txt", "r", "utf-8") # Read its contents as one large Unicode string. text = infile.read() # Close the file. infile.close() The same function is used to open a file for writing; just use "w" (write) or "a" (append) as the second argument. --- Ben Vinger <[EMAIL PROTECTED]> wrote: > Hello all > > I want to do the following in an XML file: > > XFile = open(XmlFile,'r') > for line in XFile.readlines(): > if line.find('') > 0: > print line > > However, it does not work due to extra characters > that > appear in the XML file. For example if I use the > previous code without the if condition, on a console > it looks like: > < e n d _ t i m e > > And if you output that to a text file and open that > in > a text editor, the text editor shows a square > instead > of a space in between every character. What is > going > on? > > Thanks > Ben > > > > > > ___ > > Yahoo! Photos NEW, now offering a quality print > service from just 8p a photo > http://uk.photos.yahoo.com > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] extra characters in XML
Thanks - it was exactly as you said --- Kent Johnson <[EMAIL PROTECTED]> wrote: > Most likely your XML file is 16-bit unicode, not > utf-8. When ascii text > is represented as unicode, every other byte will be > a null byte. That is > the extra character that shows up as a space or box > depending on who is > interpreting it. The utf-8 codec must be swallowing > the null bytes. > > In your code above, instead of utf-8 try utf_16_be > and utf_16_le, one of > them should work. ___ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] a class knowing its self
Hello I've been reading about how a class has access to its own 'self', so I tried the following, but it is not working as I would expect: class Skill: def __init__(self): self.history = [] def setName(self, skill): self.name = skill def getName(self): return self.name # Assigning data to my class: SkillNames = [r'python', r'apache', r'mysql'] #a.) python = Skill() python.setName('python') print python.getName() #b.) for s in SkillNames: s = Skill() s.setName(s) print s.getName() Why does a work and b not? b returns: <__main__.Skill instance at 0x401e260c> <__main__.Skill instance at 0x401e230c> <__main__.Skill instance at 0x401e23ec> why does b not return the names of the 3 instances of Skill? Thanks Ben ___ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] a class knowing its self
Yes, you are right, - Shuying Wang's suggestion fixed the immediate problem, but there is still someting wrong with my code - maybe I'll ask about it again later. --- Ewald Ertl <[EMAIL PROTECTED]> wrote: > > > Have a more precisely look at your code. > s.getName() does just return, what you have put into > the class with setName(). ( Reassignment of a > variable to > something different what you intended ). ___ NEW Yahoo! Cars - sell your car and browse thousands of new and used cars online! http://uk.cars.yahoo.com/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] passwords in scripts
Hello I've written a couple of scripts that check log files on our WIndows and Unix servers. These scripts have plain text passwords in them, so anyone who can access the filesystem of the Windows server that runs the scripts can discover the passwords of the servers. Is there a way to hide/encrypt these passwords? Or can the scripts be converted to compiled code in order for the passwords to be hidden? Thanks Ben ___ Win a BlackBerry device from O2 with Yahoo!. Enter now. http://www.yahoo.co.uk/blackberry ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passwords in scripts
Hi Ivan I'm not sure I understand what you are saying here. Surely if the file is compiled it can just run (and will only need to be RE-compiled when I have to change the code (such as when one of the servers has their password changed). I would never need to de-compile, because I'll just keep a copy of the file on a memory stick, edit it there, compile it and replace the current compiled file with the newly compiled file. Not that I know anything about compiling Python programs, I just want to know if this is a possibility Thanks Ben --- Ivan Furone <[EMAIL PROTECTED]> wrote: > 2006/1/21, Ben Vinger <[EMAIL PROTECTED]>: > > Hello > > > > I've written a couple of scripts that check log > files > > on our WIndows and Unix servers. These scripts > have > > plain text passwords in them, so anyone who can > access > > the filesystem of the Windows server that runs the > > scripts can discover the passwords of the servers. > > Is there a way to hide/encrypt these passwords? > Or > > can the scripts be converted to compiled code in > order > > for the passwords to be hidden? > > > > > > Thanks > > Ben > > > > > > Hello, > Compiling a file in python is a big time > loss,because there's not a > built-in function for decompiling,but you can just > use the 'dis'module > for disassembling it and the result is always > different from the > original,because it uses Abstract Source Tree syntax > in spite of > Python language for translating the bytecode;on the > other hand it > wouldn't secure the file itself from being accessed > but makes it > useless IMHO.Thus,with a slight impact on > complexity,a module with the > crypted passwords would be imported, which would > proceed for checking > the passwords and exporting them in a StringIO > object at runtime.For > enhancing security,once used it could be removed and > used again when > needed,without removing the scripts themselves.You > can check the > 'crypt' module for this task. > Cheers, > Ivan > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Win a BlackBerry device from O2 with Yahoo!. Enter now. http://www.yahoo.co.uk/blackberry ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passwords in scripts
Hi Danny The Unix servers are ancient HP-UX ones. I doubt if an SSH implementation for them exists, but it is not worth my while trying to find out, because I will not be allowed to install anything on them (or even suggest it). So I access them using telnetlib: host = 'hpserver' user = 'backupuser\r' password = 'backuppassword\r' telnetConnection = telnetlib.Telnet(host) telnetConnection.read_until('login: ') telnetConnection.read_until('Password: ') telnetConnection.write(password) menu = telnetConnection.read_until('Please Enter choice :') etc - doing the things programatically what I would have done if I opened a regular telnet session On the Windows servers the scheduled task I use runs with my domain logon credentials. This is fine for the majority of the servers, but some are in other domains where my credentials don't do the job. For them, I just open a connection to the ipc$ share in advance, like so: os.system(r'net use \\farserver\ipc$ /u:fardomain\administrator farpassword') The information about all the backup results is finally served as a single web page, so anyone can see at a glance whether the backups worked. This can also easily be emailed out, or warnings can be sent. But surely my problem is a very common one. Every web-app must supply a username and password to make a connection to its backend database, for example. Thanks Ben --- Danny Yoo <[EMAIL PROTECTED]> wrote: > I guess one question might be: why are the passwords > there in the first > place? *grin* > > > It's usually a good idea to try avoiding hardcoding > things in a program, > and that goes for passwords too. If you're using > passwords to connect to > the Unix servers, you might want to consider looking > at Keychain: > > http://www.gentoo.org/proj/en/keychain/ > > to avoid having to do manual password entry. > Alternatively, 'ssh' can > be used to run remote commands on a Unix server. > There's a good example > of this here: > > http://www.jdmz.net/ssh/ > > > If you could tell us more details on why those > passwords are there, we > might have some better suggestions. > > > Good luck! > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passwords in scripts
--- Alan Gauld <[EMAIL PROTECTED]> wrote: > command line arguments? > > $ startapp -d mydb -l user/password & > > That way they are > 1) kept secret(especially if you turn shell history > off ;-) and > 2) can be changed every time you restart the server > app and > 3) you can have production and test databases > running simultaneously... These are good points, but what if the server is bounced when I'm on holiday (or everyone who might enter the password is asleep). My own little app isn't critical, but I can't see this do the trick for high profile web sites and similar. ___ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] passwords in scripts
Compiling is certainly helpful in my case, and I did not realise how simple it was until you explained it. I estimate that most of our MCSEs will not know about the strings command or attempt to look inside something like test.pyc for a password. As for users, I'll be amazed if they tried it. And real crackers - I think our network/firewall people know what they are doing, so I assume crackers are kept out. So, yes, I will use this until I've done something with crypt and/or expect. Finally, regarding changing the policy about telnet - it looks to me like the network where I am (I'm very new), is secure on the networking side however lax it might be on the server side. It is 100% switched, which means that only by controlling a switch can cleartext stuff be seen, and the switches are well-protected (also physically). So while I might agree with everyone who mentioned it, I will leave the Unix security to whoever in our large organisation's concern it is. I just want to avoid endangering it myself. Thanks Ben --- Danny Yoo <[EMAIL PROTECTED]> wrote: > > > On Tue, 24 Jan 2006, Ivan Furone wrote: > > > I'm not sure I understand what you are saying > here. Surely if the file > > is compiled it can just run (and will only need to > be RE-compiled when I > > have to change the code (such as when one of the > servers has their > > password changed). > > Hi Ivan, > > But the issue is that hardcoding passwords in a > program doesn't really > protect that password from exposure. For example: > > ## > bash-3.00$ cat test.py > message = "hello, this is a test" > bash-3.00$ python > Python 2.3.3 (#1, Nov 7 2005, 22:36:37) [C] on > sunos5 > Type "help", "copyright", "credits" or "license" for > more information. > >>> import test > >>> ^D > ### > > > Doing the import will cause test.py to be compiled > to 'test.pyc': > > ## > bash-3.00$ ls -l test.pyc > -rw-r--r-- 1 dyoo other143 Jan 24 > 10:55 test.pyc > ## > > > But watch what happens here: > > ## > bash-3.00$ strings test.pyc > hello, this is a testN( > message( > message( > test.pys > ## > > Our secret string shows right up! > > > > This works even if we're talking about C code: > > /**/ > bash-3.00$ cat test.c > #include > int main(int argc, char** argv) { > char *msg = "hello"; > } > bash-3.00$ gcc test.c > bash-3.00$ strings a.out > hello > /**/ > > > So the fact that we're "compiling" code doesn't do > anything significant to > add security: those string literals are ripe for the > taking for anyone > competent enough to use the 'strings' command. So > that's what we're > trying to warn you about. Compiling code is not a > magic wand to obscure > secrets. > > > Hope this helps! > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] mod_python and other web frameworks
--- Intercodes <[EMAIL PROTECTED]> wrote: > List: I am still open to suggestions. Being also keen to write better web apps in Python, I've spent a considerable amount of time reading about this (and it is indeed confusing), I've opted to try out something like Pylons or Turbogears. One thing I will say though, is that most of the frameworks you've read about can be run on top of mod_python. So mod_python is not one of the lot - it is essential on Apache unless you opt to use CGI or FCGI. But as I understand it, you would always opt for mod_python over CGI or FCGI on a high-traffic website, though CGI or FCGI is of course fine for smaller things. But mod_python is not so easy to work with and it will only work on Apache. So it seems best to choose something else and run that through mod_python when you're on Apache. ___ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Trapping a Dr Watson error
Hello I have a script based on: http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/pywin32/Windows_NT_Eventlog.html It collects eventlogs data from many Windows servers. I know how to handle normal Python Tracebacks, but my script bombs out with a Dr Watson error when connecting to one particular server. (It even runs fine against the Application log of this server, but bombs out on the System log). Anyways, I want to know if it is possible to trap, handle and survive a Dr Watson error programatically Thanks Ben ___ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python help
Why are these homework programming challenges so recognisable? It boils down to: Write a function that that uses X and Y techniques. The function may be hard and challenging to write but doesn't ever do anything interesting or anything that is useful and complete on its own. I realise teachers have to test mastery of certain techniques, but they seem to lack the imagination. Especially with modern languagues like Python, where you can write a whole program that actually does something usefull using only a few lines of code it should not be necessary to ask these kinds of dull questions. Just stick at it Natasha, it is far more interesting when you the programming challenge has to accomplish a real result. Ben --- Natasha Menon <[EMAIL PROTECTED]> wrote: > Hi, > > I have a few doubts in python programming. C if > any of u can help me out. > > 1. > In a file called string_stuff.py i have to write a > function called frequencies that takes a string as a > parameter and returns a dictionary where the keys > are the characters from the string and each value is > an integer indicating the number of times the key > appeared in the string. > > 2. > Similary in the same file string_stuff.py, have to > write a function called locations that takes a > string as a parameter and returns a dictionary where > the keys are the characters from the string and each > value is a list indicating the indices in the string > at which the key appears, sorted in increasing > order. > > 3. > In the same file string_stuff.py, write a function > called concordance that takes an open file as a > parameter and returns a dictionary where the keys > are the strings from the file and each value is a > list of line numbers of the lines in which the key > appeared, sorted in increasing order. Start counting > at 0. Each line number should appear at most once in > a list, even if a word appears twice on a line. You > may assume that the input consists only of > alphabetic letters (a-z, A-Z) and whitespace. > > > Id really appreciate if you could help me on these > small question. I am tryin to learn to program in > python. > > Thanks, > Natasha > > > - > Brings words and photos together (easily) with > PhotoMail - it's free and works with Yahoo! Mail.> ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How can a function know where it was called from
Hello I want myfunction in the pseudocode below return something different if it was called from indexfunction. def indexfunction(): blah def myfunction(): x = 'whatever' if : return x else: return + x + Thanks Ben ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How can a function know where it was called from
Thanks to all who responded. I ended up using a sender parameter as suggested by Andre and Alan, as this was very simple to do. Ben ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to monitor streaming data from the internet via modem?
On 3/8/06, Alan Gauld <[EMAIL PROTECTED]> wrote: Ethereal is one well knownand powerful one, but there are others which may be simpler touse. Yes, with Ethereal comes a command-line version called tethereal, which I've used within Python on both Windows and Linux. It worked nicely for trafic analysis, but if you're interested only in the clear text passing through the line, I'd think of using netcat. (Sorry Alan, my previous attempt went straight to you instead of the list) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Build your own web server in three lines of code
The nice-looking, revamped Python web site states that you can do this, but does not go on to say how. Does anyone know? On an OT note, I've recently seen how it can be done in a shell script: http://www.debian-administration.org/articles/371 Ben ___ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] TypeError: dict objects are unhashable
Hello I want to create a dictionary (from SQL usernames) of the format: accounts = { ('psmit', '123456'): 'psmit', ('rmatt', 'mypass'): 'rmatt', } So I have: accounts = {} UserCursor.execute(sqlstr) rows = UserCursor.fetchall() UserConn.commit() for row in rows: U = row['User'] P = row['Password'] InnerDict = {} InnerDict[U] = P accounts[InnerDict] = U But I get: TypeError: dict objects are unhashable Unfortunately, I just can't see what I'm doing wrong Thanks ___ NEW Yahoo! Cars - sell your car and browse thousands of new and used cars online! http://uk.cars.yahoo.com/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor