Re: [Tutor] How to run a small python client-server on Google App Engine
I suppose you could run something persistent on a reserved instance at Google App Engine, but typically they kill any process running longer than 30 seconds. And the persistent servers aren't free. On Apr 19, 2012 7:36 AM, Surya K sur...@live.com wrote: I wrote a small python Client-Server program.. (I use python 2.7) and want to make it real. I mean, I want to put the server on Google App Engine.. I went through it and found that, I need to use Google API so that it should work on GAE. So, How could I create such a small Google App Engine's app. I mean.. Can anyone help me on it.. (Assuming that there is a server.py which just shows how many clients are connected to it, how do I make a app of such program) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python with HTML
If you're hoping for something like PHP that can be parsed inline with html, you're out of luck. It's also bad design to mix business logic with your presentation layer. You might want to look into some frameworks like django to help you along. On Jan 28, 2012 2:04 AM, t4 techno opentechblog...@gmail.com wrote: hi everyone, I want to make a web page which has to include some python script and html tags as well, am not getting how to do that . I searched some articles but cant understand them . is there anything like linking an external html file into python script ? Can u please help for same waiting for your instructions or some links that can help me Regards ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Why do you have to close files?
On 1/26/12 3:20 PM, amt wrote: Exercise 17, extra credit 6 Learn python the hard way: Find out why you had to do output.close() in the code. Code: output.close() input.close() I don't get it. If you don't close input and output it works exactly the same as if you would close them, so why do you have to do output.close() and input.close()? Also does it matter if you do: input.close() and then output.close()? Is there an order to follow? There's no order to follow, and it's really more about cleaning up after yourself than being a necessity. If you were writing to real files, your operating system would limit how many open files you could have at any time, so you want to make sure you close file handles you're no longer using. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Setting Network settings from Python/Djang
Well DNS would be easy, just modify /etc/resolve.conf ... the other files you need to modify would depend on your distro because they all do something slightly different it seems. On Jan 22, 2012 3:25 AM, Ganesh Kumar bugcy...@gmail.com wrote: I'm working on a simple web interface for an embedded computer. The computer will ship with a static default ip that will then need to be updated by the install tech who may not be tech/linux savvy. Basicly I need to change the following system settings from a Django app. 1. IP Addres 2. Subnet 3. Default Gateway 4. DNS Servers 12 I realize that I can could just overwrite the config files in linux but I was wondering if there is a more Python way of doing it. I want any ready to use module is there, please guide me. -Ganesh. Did I learn something today? If not, I wasted it. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Question about sorting a list within a dictionary within a list
I'm using the Bono library for talking to EC2, and I'm getting a list of EC2 instances back in a list called reservations. Each element in the list is a dictionary of information. One of those dictionary elements is a list called 'instances', and I only ever care about the first entry. That instances[0] value is a dictionary, which holds a key I want to use to sort the base reservations list. I found this helpful bit for sorting a list of dictionaries by a key within the dictionaries: http://stackoverflow.com/questions/72899/in-python-how-do-i-sort-a-list-of-dictionaries-by-values-of-the-dictionary ... this works great if you just have a list of dictionaries. I'm not sure how to go deeper within that to sort my data without iterating through the entire 'reservations' list and building an entirely new list. Maybe it would be easier, but I'm just curious if it's possible without messing with my main 'reservations' list. My current code looks like this: (it's a views.py file) from django.http import HttpResponse import boto.ec2 from operator import itemgetter def index(request): conn = boto.connect_ec2() reservations = conn.get_all_instances() # this is where I'm trying to sort everything res_sorted = sorted(reservations, key=itemgetter('launch_time')) output = 'table' output += 'tr' output += 'thState/th' output += 'thLaunched/th' output += 'thPublic Hostname/th' output += 'thPublic IP/th' output += 'thPrivate Hostname/th' output += 'thPrivate IP/th' output += '/tr' for reservation in res_sorted: instance = reservation.instances[0] output += 'tr' output += 'td' + instance.state + '/td' output += 'td' + instance.launch_time + '/td' output += 'td' + instance.public_dns_name + '/td' output += 'td' + instance.ip_address + '/td' output += 'td' + instance.private_dns_name + '/td' output += 'td' + instance.private_ip_address + '/td' Ideally, I'd like to make each table column 'sortable' so the user can click on state/launched/etc (I may add more columns in the future), but I'm not sure how to search deeper within the 'reservations' list for the sorted() call to get at the 'launch_time' element within the instaces[0] dictionary. Also, I'm sure there are much better ways to do the display logic, but I'll tackle that another time. Thanks for any pointers, Ian ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] time zone conversion
Hi all, Been trying to wrap my head around some datetime vs time stuff with regards to parsing a string as a date plus time with a timezone offset. This is the string I'm given: 2010-01-22T00:14:33.000Z And I can use time.strptime to parse out its individual elements, but then I need to adjust that time, in UTC/Zulu to my local time zone. Here's what I'm currently trying: old_launch_time = '2010-01-22T00:14:33.000Z' os.environ['TZ'] = 'UTC' time.tzset() launch_time = time.strptime(old_launch_time, '%Y-%m-%dT%H:%M:%S.000Z') os.environ['TZ'] = 'US/Pacific' time.tzset() print 'old time: ' + old_launch_time print 'new time: ' + time.strftime(%Y-%m-%d %H:%M:%S, launch_time) output: old time: 2010-01-22T00:14:33.000Z new time: 2010-01-22 00:14:33 But the different tzset() calls are not adjusting based on the 7 or 8 hour difference. I know that all incoming dates/times are coming to me in UTC. I just can't seem to get a good handle on how to properly convert it to my own time zone. Thanks, Ian ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about sorting a list within a dictionary within a list
On 08/01/2011 01:03 PM, Peter Otten wrote: ian douglas wrote: I'm using the Bono library for talking to EC2, and I'm getting a list of I cannot help you with the django or boto part. Well, I suppose that using django/bono wasn't really relevant to the question. I appreciate the feedback though, I'll definitely keep it in mind for future projects. The sort() and mykey() stuff you proposed looked neat. I'll dig into that stuff more to see how it works when I finish this project. I appreciate the LEGAL_SORTKEYS bit too, it was on my to-do list as well. In the end, I ended up flattening things a little, instead of having a list of objects, and those objects holding a list of instances, and each of those instances being objects themselves: reservations_bulk = conn.get_all_instances() reservations_unsorted = [] ; for reservation in reservations_bulk: instance = reservation.instances[0].__dict__ reservations_unsorted.append(instance) reservations = sorted(reservations_unsorted, key=itemgetter('launch_time')) I'm sure there's an even cleaner way of doing the for loop too? I hadn't seen the __dict__ property before for objects, and that allowed me to just build a simple list of dictionaries, which I could then run through the itemgetter() solution I'd found on StackOverflow. Ian ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Accessing Specific Dictionary items
On 08/01/2011 03:05 PM, Mike Nickey wrote: Hi all, I'm trying to access and use specific items within a dictionary that is returned but am having issues in doing so. [{'city': 'Sunnyvale', 'region_name': 'CA', 'area_code': 408, 'metro_code': 'Santa Clara, CA', 'country_name': 'United States'}] How can I populate a list of many different returns so that I have a list that contains all the cities and in line with the item that is referenced. The first step is to populate the list unsorted as it needs to be in correlation to the item that it came from. Thanks for your help. Could you give us examples of what you want the list to look like? It will help us direct you to an answer. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to replace the '\'s in a path with '/'s?
Try a double backslash replace('\\','/') On Jul 30, 2011 10:30 PM, Richard D. Moores rdmoo...@gmail.com wrote: 64-bit Vista Python 3.2.1 I would like to write a function that would take a path such as 'C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf' and return 'C:/Users/Dick/Desktop/Documents/Notes/College Notes.rtf' . I've tried this: def test(path): return path.replace('\', '/') print(test('C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf')) gets me File c:\P32Working\untitled-5.py, line 2 return path.replace('\', '/') ^ SyntaxError: EOL while scanning string literal Process terminated with an exit code of 1 Thanks, Dick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python editor for Ipad
Yes, Cloud9 supports running/debugging/testing. They've also got github support for pulling in your projects. It's a pretty clever tool. On 07/21/2011 01:24 PM, Tahir Hafiz wrote: Cloud9 seems interesting as a browser based IDE. Do you know if there is a way to run Python code as well create/edit it? Thanks, Tahir On Thu, Jul 21, 2011 at 5:30 PM, Corey Richardson kb1...@aim.com mailto:kb1...@aim.com wrote: Excerpts from James Reynolds's message of Thu Jul 21 10:40:53 -0400 2011: I might have to discuss some routines I've written in Python (and possibly C). It would be easier to whip out the Ipad and show them some of the things I've done, rather than a bulky laptop. I could of course PDF everything with highlighting off of eclipse, but ideally Ideally I would prefer a way for the user to interact with the text, rather than an image. So basically, an IDE or text editor with syntax highlighting for python. If you have any thoughts, I would greatly appreciate it! If you have a browser, Cloud9 IDE might be able to do it. Or you could use pygments to render the text to HTML and ... do you even have filesystem access on an ipad? (This is assuming you don't want your code out public for the whole world to see). So your best bet would probably be Cloud9 or a similar product. -- Corey Richardson Those who deny freedom to others, deserve it not for themselves -- Abraham Lincoln ___ Tutor maillist - Tutor@python.org mailto:Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python editor for Ipad
On 07/21/2011 01:46 PM, Corey Richardson wrote: Excerpts from ian douglas's message of Thu Jul 21 16:44:17 -0400 2011: Yes, Cloud9 supports running/debugging/testing. They've also got github support for pulling in your projects. It's a pretty clever tool. Could you share your secret? I didn't dig enough to figure it out. I saw the Run button and its configuration, but it looks like it wants a JS file and args? Or...maybe not? Ah, my bad. Creating files should be allowed, but running *Python* files seems to still be on their TODO list as of March 23rd. Sorry for the misinformation. As soon as they Email me a password recovery message, (I signed up in May at Google IO), I can get more information to the list. -id ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Strategy to read a redirecting html page
On 05/31/2011 04:34 PM, Hugo Arts wrote: On Wed, Jun 1, 2011 at 1:00 AM, Karimkarim.liat...@free.fr wrote: Hello, I am having issue in reading a html page which is redirected to a new page. I get the first warning/error message page and not the redirection one. Should I request a second time the same url page or Should I loop forever until the page content is the correct (by parsing it) one? Do you have a better strategy or perhaps some modules deal w/ that issue? I am using python 2.7.1 on Linux ubuntu 11.04 and the modules urllib2, urllib, etc... The webpage is secured but I registered a password manager. urllib2 works at the HTTP level, so it can't catch redirects that happen at the HTML level unfortunately. You'll have to parse the page, look for ameta http-equiv=refresh tag, and fetch the URL from it. That's a pretty simple parsing job, probably doable with regexes. But you're free to use a proper html parser of course. Also, given that the 301/302 redirect you get in that response could ALSO redirect, I'd suggest looping until a counter is exhausted, so you don't end up in an infinite loop if pages redirect to each other. -id ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Interview Questions..
If I were interviewing for a Perl or PHP position, then yes. However, if I just wanted to see if they knew the algorithm, I'd let them use whatever language they were most comfortable in, provided those of us interviewing also knew the language. I think C++ is more common now for data structures and algorithms. -id On 05/26/2011 10:34 AM, Prasad, Ramit wrote: When giving an interview, I ask interviewees to write samples of code. Would you ask your code samples for a python (or XXX language) position do you have them code it in...C or actually code it in Python (or XXX language)? Another favorite of mine was asking a candidate to write a piece of code that took a paragraph of text as a parameter, and while maintaining the order of the sentences, reverse the order of the words in each sentence. I ask because this would be fairly easy in Python (admitted my interview solution would have problems with handling punctuations), but probably a lot more complex in something like C. Is C still the standard interviewing basis for the computer science basics (e.g. data structures, algorithms, etc)? Ramit ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Clunky Password maker
On 05/26/2011 02:45 PM, Wolf Halton wrote: Now I am looking at how to make it have an admin function to set the valid characters, and have a way to output the password into main() Simple, just learn to use the 'return' statement: [code] def new_pass(p): pp = int(raw_input(Enter the length you want your password to be:[%i] % (p)) or p) # length of password chosen or default length new_password = generate_new_pass(pp) print \nYour New Password is: %s\n % new_password return new_password def generate_new_pass(userlength): valchars = string.ascii_letters + string.digits + string.punctuation series = list(valchars) rr = random.sample(series, userlength) return join(rr) def main(): my_new_password = new_pass(default_length) [/code] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Interview Questions..
To expand on Martin's questions, when I've interviewed in the past, I've asked (or been asked as an interviewee) questions that investigate critical thinking, like those silly-sounding questions of how many golf balls would fit in a bus or how many windows are there in Seattle. Those kinds of questions are meant to gauge how you think through a problem, not necessarily coming up with the correct answer. When giving an interview, I ask interviewees to write samples of code. A popular one is to write the Fibonacci algorithm in code, or how to write a quick-sort or merge-sort algorithm. Being familiar with some of these computer science principles will show your familiarity with lower level understandings of how software works. It also helps identify people who are self-taught and only know higher level operations, and those who have gone to college/university for computer science or formal software development training. Another favorite of mine was asking a candidate to write a piece of code that took a paragraph of text as a parameter, and while maintaining the order of the sentences, reverse the order of the words in each sentence. So The sky was blue. The grass was green. would become blue was sky The. green was grass The. Good luck on your interviewing. -id On 05/24/2011 03:11 PM, Martin A. Brown wrote: Hi there, : Hey I'll be appearing for Job Interviews and wondering if anybody : of you appeared for a Python Interview Or if on the other end as : an interviewer. Can you please share the questions asked? : That will be of great help :) I would point out that there are many types of interviews. There's the technical screen, which is what it sounds like you are asking about, but there are other types of interviews that tend to focus on drawing out your approach to problems or your mindset. With the latter type of interview, I would only suggest that you know yourself. If however, you are worried about the technical content of an interview, it is possible that having my list of questions may help you. It may also hinder you, because the set of questions that I ask may differ dramatically from another technical interviewer. We are a fickle lot, prone to ask questions we (think we) know the answers to, which may differ from what you know [0]. With that said, here's a subset of the questions that I commonly use when interviewing candidates for a technical screen--I would rarely ask all of these. * What's your favorite stdlib module? (And, why?) * Distinguish a dict() and a set(). When would I use which? * Distinguish a tuple() and a list(). When would I use which? * What's the risk of 't = sys.stdin.readlines()'? * What's an iterator? Why would I care? * When should I use 'with'? Is there any advantage? * What's a regex? Why not just use string matching? * What does os.stat() return? For what is this useful? * What's WSGI? Why would I use it? * What are ElementTree and lxml? * What's a decorator? * What (unit) testing tools exist and how would I use them? * What does 'raise' do? What does 'pass' do? * Describe Python's inheritance model. And, some others that are geared more toward those who have written network (or SQL) applications: * What's a file descriptor? * What's a socket? * How do I create a listening socket in Python? * What's a signal? * How do I talk to a SQL DB from Python? Any other DBs? * What tools are available for calling an external process? * What's a queue? * What's a thread? Are there any (special) concerns about threads I should have as a Python programmer? If you have some familiarity with Python (particularly in a Unix-like environment) many of these questions would be familiar to you. I would get some idea of your facility with the language and the underlying operating system from the accuracy and comfort with which you answered. You might also find one or two of these (mis)leading and might want to tell me about corner cases that you as a developer have faced. That would also be interesting to me as a technical interviewer. -Martin [0] http://www.quotationspage.com/quote/12220.html ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Making a script part of the terminal
To expand further, some distributions of Linux set a 'bin' path under your home folder as part of your native PATH, even if it doesn't exist. So if your Linux username is, say, mscott, see if echo $PATH already includes something like /home/mscott/bin in the path already. If so, simply create a bin folder: mkdir ~/bin and then place your Python scripts within that folder, and follow Edgar's other advice about adding #!/usr/local/bin/python and using chmod +x filename.py etc. If you're on a non-Linux platform, I'm sure others can provide further help. -id On 05/20/2011 11:03 AM, Edgar Almonte wrote: hey ! i can answer that ! birst in the fist line of you script put something like this #!/usr/local/bin/python change the path for where you have python ( try using 'whereis python' ) sencond make the file executable add the +x attribute ( using chmod ) third put the script in some place and and that path to the PATH enviroment variable. good luck On Fri, May 20, 2011 at 1:43 PM, michael scottjigenbak...@yahoo.com wrote: Okay, my title might be undescriptive, let me try to explain it better. I want to take a script I've written and make it usable by typing its name in the terminal. Perfect example is the python interpreter. You just type in the word python to the terminal and then the interpreter runs. I know other programs can do this as well (like mozilla or nautilus or rhythmbox). So how do I make my scripts executable from the terminal? What is it about you... that intrigues me so? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] BaseHTTPServer, how do catch/trap broken pipe errors?
Hey all, I released my short URL engine last night and it works great. The only problem I'm having now is that it's throwing LOTS of 'broken pipe' errors, which as I understand from looking at raw socket docs in Python, should throw a trappable exception. This might be a little more 'advanced' than the average tutor questions, so I posted some details at StackOverflow.com just so I could keep the huge code sample and error messages off the mailing list. I'd appreciate it if anyone could help me figure out where the best place is to wrap a try/except call, and which exceptions I should be looking for. http://stackoverflow.com/questions/6063416/python-basehttpserver-how-do-i-catch-trap-broken-pipe-errors Cheers, Ian ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] short url processor
Hey folks, I'm rewriting a short url processor for my job. I had originally written it as a multi-threaded Perl script, which works, but has socket problems causing memory leaks. Since I'm rebuilding it to use memcache, and since I was learning Python outside of work anyway, figured I'd rewrite it in Python. I'm using BaseHTTPServer, overriding do_GET and do_POST, and want to set up a custom logging mechanism so I don't have to rewrite a separate log parser, which I'll eventually rewrite in Python as well. The problem I'm having, though, is that the BaseHTTPServer setup is outputting what appears to be an apache-style log to STDOUT, but the logging.debug or logging.info calls I make in the code are also going to STDOUT despite my attempt to use logging.basicConfig() overrides and setting a filename, etc. Here's the basics of what I'm doing. Forgive my code, I've already been told it's ugly, I'm new to Python and come from a background of Perl/PHP. import struct import string,cgi,time import psycopg import logging import re import memcache from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer from time import strftime,localtime class clientThread(BaseHTTPRequestHandler): def log_my_request(self,method,request,short_url,http_code,long_url,cached,notes): logging.debug(%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s, self.client_address[0], time.strftime(%Y-%m-%d %H:%M:%S,localtime()), method, # get or post request, # requested entity short_url, # matching short_url based on entity, if any http_code, # 200, 301, 302, 404, etc long_url, # url to redirect to, if there was one cached, # 'hit', 'miss', 'miss-db', 'error' notes # extra notes for the log file only ) return def do_GET(self) # logic goes here for finding a short url form memcache, then writing the appropriate # output data to the socket, then logging happens: self.log_my_request(getpost,orig_short_url,short_url,'302',long_url,'hit','') return def main(): if mc.get('dbcheck'): # memcache already has some data print(memcache already primed with data) else: # nothing in memcache, so load it up from database print('Connecting to PG') cur.execute(SELECT count(*) FROM short_urls) ; mycount = cur.fetchone() ; print(fetching %s entries, mycount) cur.execute(SELECT short_url,long_url FROM short_urls) giant_list = cur.fetchall() # cache a marker that tells us we've already initialized memcache with db data mc.set('dbcheck','databasetest',0) # I'm sure there's a MUCH more efficient way of doing this ... multi-set of some sort? for i in giant_list: if i[0]: if i[1]: mc.set(i[0], i[1]) print(finished retrieving %s entries plus set up a new dictionary with all values % mycount) #{{ set up the socket, bind to port, and wait for incoming connections try: server = HTTPServer(('',8083), clientThread) print 'short url processing has begun' # this is where I try to tell Python that I only want my message in my log: # no INFO:username prefix, etc., and also to write it to a file logging.basicConfig(level=logging.DEBUG) logging.basicConfig(format='%(message)s', filename='/tmp/ian.txt') server.serve_forever() except KeyboardInterrupt: print '^C received, shutting down server' server.socket.close() My code runs without any errors, though I have left some code out of this Email that I didn't feel was relevant such as the logic of seeing if a short url exists in memcache, trying to fetch from the db if there was no match, and if the db lookup also fails, force-deleting short urls from memcache based on other instructions, that sort of thing. None of it deals with logging or the BaseHTTPServer code. To recap, the code runs, redirects are working, but ALL output goes to STDOUT. I can understand that print statements would go to STDOUT, but the BaseHTTPServer seems to want to write the Apache-style log to STDOUT, and my logging.info() call also prints to STDOUT instead of my file. I'd love to hear any thoughts from people that have had to deal with this. The logging is the last piece of the puzzle for me. Thanks, Ian ___ Tutor maillist - Tutor@python.org To
Re: [Tutor] short url processor
On 05/13/2011 05:03 PM, Alan Gauld wrote: How do you know they are going to stdout? Are you sure they aren't going to stderr and stderrr is not mapped to stdout (usually the default). Have you tried redirecting stderr to a file for example? As I say, just some thoughts, Thanks for your thoughts, Alan. I had done some testing with cmdline redirects and forget which is was, I think my debug log was going to stdout and the apache-style log was going to stderr, or the other way around... After a handful of guys in the #python IRC channel very nearly convinced me that all but 3 stdlib libraries are utter worthless crap, and telling me to download and use third-party frameworks just to fix a simple logging issue, I overrode log_request() and log message() as such: class clientThread(BaseHTTPRequestHandler): #[[[ def log_request(code, size): return def log_message(self, format, *args): open(LOGFILE, a).write(%s\n % (format%args)) ... and now the only logging going on is my own, and it's logged to my external file. Overriding log_request means that BaseHTTPServer no longer outputs its apache-style log, and overriding log_message means my other logging.info() and logging.debug() messages go out to my file as expected. -id ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] short url processor
On 05/13/2011 05:03 PM, Alan Gauld wrote: As I say, just some thoughts, I *am* curious, Alan, whether you or anyone else on the list are able to help me make this a little more efficient: cur.execute(SELECT short_url,long_url FROM short_urls) giant_list = cur.fetchall() for i in giant_list: if i[0]: if i[1]: mc.set(i[0], i[1]) At present, we have about two million short URL's in our database, and I'm guessing there's a much smoother way of iterating through 2M+ rows from a database, and cramming them into memcache. I imagine there's a map function in there that could be much more efficient? v2 of our project will be to join our short_urls table with its 'stats' table counterpart, to where I only fetch the top 10,000 URLs (or some other smaller quantity). Until we get to that point, I need to speed up the restart time if this script ever needs to be restarted. This is partly why v1.5 was to put the database entries into memcache, so we wouldn't need to reload the db into memory on every restart. Thanks, Ian ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] un-buffered web output
Hey List, In Perl, I can manipulate a special variable called $| to control buffered output, even on web pages, so I can watch something run (like CGI processes reading files or running system commands) as Perl processes it (pseudo real-time), as opposed to languages like PHP which buffers all output and draws it all in one shot. I saw this on Stack Overflow, and was curious if this is still the best practice to do the same thing in Python? sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) Thanks, Ian ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help with dates in Python
I'm new to the language as well, but I think you're missing your indentation after each of your 'if' conditions? On 03/09/2011 10:34 AM, nookasree ponamala wrote: if t max: maxyr = max should be indented if t min: minyr = min should be indented t = (a,b,maxyr,minyr) tot.append(t) print t ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] remote code execution
Sounds like it should be possible via SSH, but I have no idea how you'd set that up within Eclipse. On 02/15/2011 10:50 AM, S de Haan wrote: For instance, Im working on my local machine with Eclipse, but using the Interpreter that is on one of my Linux Servers. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with range of months spanning across years
It bugs me that so many people are quick to jump on the we wont' do your homework bandwagon -- I was accused of the same thing when I posted a question to the list myself. I've been programming professionally for many years but learning Python in my spare time... I sent this reply to Sean privately, but frankly I'm so annoyed at the 'homework' replies, I figured I'd just post it here. I'm still very junior to Python, but this seems to work for me using recursion. I'm sure there's a much more elegant way of doing this, but like I said, I'm still pretty new to the language. def makelist(startmonth,startyear,endmonth,endyear): mylist = [] if (startyear == endyear): for month in range (startmonth,endmonth+1): mylist += [(startyear,month)] else: for month in range (startmonth,13): mylist += [(startyear,month)] mylist += makelist(1,startyear+1, endmonth, endyear) return mylist ; print makelist(8,2009,1,2010) I'd love to hear any replies from the experts on the list on how to make this more efficient in Python 'cause I'm still learning myself. On 02/01/2011 05:14 PM, Elwin Estle wrote: --- On Tue, 2/1/11, Sean Carolanscaro...@gmail.com wrote: What would be the most straightforward way to create a list of year/month pairs from start to end? I want to end up with a list of tuples like this: mylist = [(2009, 8), (2009, 9), (2009, 10), (2009, 11), (2009, 12), (2010, 1)] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Accessing a secured webpage
If it's HTTP basic_auth, you could try this method too: http://username:passw...@domain.com/page.html On 01/28/2011 01:54 PM, Karim wrote: Hello, I want to create a client to access a webpage. But when I access it interactively there is a dialog box which ask for login and password. I want to access it in batch via python but I could only found a basic example: ||#||!/bin/env|| ||python| |#|| ||-*-|| ||coding:|| ||utf-8|| ||-*-| |import| urllib2 reponse|=| urllib2.|urlopen|(|'||http||:||/||/||www||.||kernel||.||org||/||'|) xhtmldata|=| reponse.|read|() |for| num,ligne|in| |enumerate|(xhtmldata.|splitlines|()) : |print| |||%04d|| ||-|| ||%s%|(num,ligne) | I want to provide login and password via python code. The web adress is like http://website.com:8081/ddts/ddts_main. If you have link it is welcome! Regards Karim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Having a problem with markdown
Thanks Tino, It's certainly not homework, I'm learning Python after being in the Perl/PHP world for well over a decade. Trying to teach this old dog some new tricks. On Jan 26, 2011 6:47 AM, Tino Dai obe...@gmail.com wrote: On Wed, Jan 26, 2011 at 2:46 AM, ian douglas ian.doug...@iandouglas.com wrote: Hey all, I followed a tutorial on creating a very simple wiki in Python, which worked fine until the example where the instructor wanted to render the output through markdown.markdown() Here's the view code: from agwiki.wiki.models import Page from django.shortcuts import render_to_response from django.http import HttpResponseRedirect import markdown def view_page(request, page_name): try: page = Page.objects.get(pk=page_name) except Page.DoesNotExist: return render_to_response(create.html, {page_name:page_name}) content = page.content return render_to_response(view.html,{page_name:page_name,content:markdown.markdown(content)}) The problem I'm having is that the output in a browser is outputing HTML markers as lt; and gt; instead of and so the browser literally shows phello world/p. If I leave the line as it originally was: return render_to_response(view.html,{page_name:page_name,content:content}) It just prints hello world as saved in the database. I'm just not sure where to start looking for a solution here, and would appreciate any pointers. Two thing: - This sounds like homework. - This is a python mailing list, not a django mailing list Where I would start would be to investigate what the markdown class does. In addition I would read over the django documentation to see why django is doing that. It's in the django documentation, I hit that issue not too long ago. HTH, Tino ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Having a problem with markdown
Thanks, Benjamin, I figured it was a version issue, I'm just so new to Python that I didn't know where to look. Sorry for polluting the list with Django questions, I thought it was an underlying Python issue, not the framework. -id On 01/26/2011 10:10 AM, Benjamin Kircher wrote: Hi Ian. Well, I did that very same tutorial a few months ago and ran into the same issue. It's not an issue with markdown but a feature called auto-escaping. The tutorial is quite old (but nonetheless good), so back in that day auto-escaping wasn't the default in Django. Now it is. However, you might want consult the Django docs about auto-escaping http://docs.djangoproject.com/en/1.2/ref/templates/builtins/#autoescape ;) -- Benjamin ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] ideas for a simple program
With an Email address like hacker0100, your best bet might be to do what we told another user just a few days ago: Find an open-source project, and try to add a new feature to it, or fix a bug in it. That way you learn about the language, the project, and could get your name out there as a contributor if your changes are accepted by the original author. On 01/25/2011 09:25 AM, walter weston wrote: can I have some good ideas for simple programs, I have come to realize the hardest part of programming is not having a project to do and having to think of one haha ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Having a problem with markdown
Hey all, I followed a tutorial on creating a very simple wiki in Python, which worked fine until the example where the instructor wanted to render the output through markdown.markdown() Here's the view code: from agwiki.wiki.models import Page from django.shortcuts import render_to_response from django.http import HttpResponseRedirect import markdown def view_page(request, page_name): try: page = Page.objects.get(pk=page_name) except Page.DoesNotExist: return render_to_response(create.html, {page_name:page_name}) content = page.content return render_to_response(view.html,{page_name:page_name,content:markdown.markdown(content)}) The problem I'm having is that the output in a browser is outputing HTML markers as lt; and gt; instead of and so the browser literally shows phello world/p. If I leave the line as it originally was: return render_to_response(view.html,{page_name:page_name,content:content}) It just prints hello world as saved in the database. I'm just not sure where to start looking for a solution here, and would appreciate any pointers. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Exercise suggestions
For me, the quickest way to jump into a programming language was seeing a current open source project and say I wish it did this too, or that instead ... and implement it myself. Not only do you learn about the project itself, and pick up some tips and tricks along the way, you then also have a way to tell the original author about something you could contribute if others are interested. So, it's not just working on something to make it better, you do it to make it personal to your own needs instead. On 01/22/2011 01:52 PM, Elwin Estle wrote: Sure, there are tons of these sorts of apps already, but so what? Maybe you can make one that is better. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor