Re: [Tutor] ImportError: 'DLL load failed: %1 is not a valid Win32 application.'
On 2013-10-10 16:04, Sreenivasulu wrote: ImportError: 'DLL load failed: %1 is not a valid Win32 application.' Please help me how to run win32 modules in 64 bit . If I'm reading that correctly, that's not an error about running a 32-bit application in a 64-bit environment, but an error about it not being a valid 32-bit application in the first place... I have no idea what I'm talking about when it comes to Windows though, so who knows. pgpTZTFeAn4MH.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Writing Function Definitions
Hi Connor, On 2013-10-08 17:50, Connor Hood wrote: Hi, I am taking a class in order to learn Python. One of the exercises I need to do is write function definitions. I cannot figure out how to do one of them. To show you an example here is a similar problem: If m is an integer, then isPrime(m) iff m is prime.The code: # Prompts the user for an integer m and then computes and prints whether# m is prime or not. # isPrime(m): I - Bool# If m is an integer, then isPrime(m) if and only if m is prime.def isPrime(m):return False if m = 1 else isPrimeItr(1,0,m) # isPrimeItr(i,a,m): I x I x I - Booldef isPrimeItr(i,a,m):return False if a 2 else True if a == 2 and i == m +1 else isPrimeItr(i+1,a+1,m) if m % i == 0 else isPrimeItr(i+1,a,m) # print a brief description of the program followed by an empty lineprint(Computing Prime Numbers)print(Prompts the user an integer value for m and then computes and)print(prints if m is prime or not.)print() # prompt the user for a value for mm = eval(input(Enter an integer value for m: )) # print if m is primeprint(The value that, m, is a prime integer is, isPrime(m)) These are the problems I am having problem with: If m and n are integers, then anyPrimes(m,n) iff there are any prime numbers in the interval [m,n). If m and n are integers, then countPrimes(m,n) is the number of prime numbers in the interval [m,n). If anyone could help that would be great. Thank you. Your code seems totally unreadable to me (all squashed on one line). Perhaps you should consider attaching it, instead. pgpKR_p1uFbL6.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Writing Function Definitions
On 2013-10-09 11:28, Dave Angel wrote: Alan's suggestions pretty much cover mine. Make your code readable, rather than clever while you're learning. s/while you're learning// pgpjKcnwi1MeE.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HELP I need help with Python Setup or to reach Marilyn Davis
On 2013-10-02 19:01, carolynn fryer wrote: I am at the point where I am just spinning my wheels. I tried to get help with logging on but so far I am just getting frustrated. I have a problem that I brought up the first night in class but couldn't seem to get help then. Sorry if I am at the point where I am totally frustrated and I need HELP. PLEASE. I did not turn in homework because of the fact that I can not run anything without getting a syntax error. I tried setting up a path for python environment variables and a few other things but I am getting no where. Can you give me some suggestions why I can't run anything. I have windows 7 on my home computer, and windows 8 on my laptop and they are both doing the same thing. So it has to be something I am doing or not doing. I really do not like being behind/late in anything so that is making me even more frustrated. I suppose I am even more frustrated and afraid to ask because I kink of got a slap in the face last time I took a course here and the instructor would not help. But that was a way different situation, I simply could not understand his English and then he told me he did not have any patience. Excuse me but I just about died when he, an INSTRUCTOR told me that. I worked at Stanford for 25 years and to hear an instructor say those words was unthinkable. Anyway you can maybe understand my reluctance to ask for help but I need help. Any suggestions?? When I use one of the computers at school everything works just fine. Except I can not get my own computer to log on when I am there. So again that is why I said it is my system and something in my set up that I don't have. Sorry for the long note, I was just letting out a little frustration. LOL Thx for any suggestions, Carolynn Fryer ps: I know this is not the proper way to get ahold of you but I could not find nor have time to find any other way. The UCSC system is not very user friendly I genuinely have no idea what we are supposed to do with this unfocused diatribe. It would be good if you could avoid copying tutor@ to your inane UCSC-centric rants in future. You have, however, given absolutely no information that could help anyone in diagnosing your problem. I don't have the patience to wade through this contextless rant. In future: - Nobody on this list cares about what you have to say about UCSC; - Please get to the point; - Please include actual examples of error messages you face instead of just describing them. Thanks. pgpkVvFWcEzq6.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] AntiSpam measures circumventing
On 2013-09-25 13:54, Steven D'Aprano wrote: And even that, I'm wondering if I'm being too cautious. Well, if you post on mailing lists, undoubtedly your e-mail has been posted in plaintext somewhere. I personally have my e-mail in plaintext on chrisdown.name, and very rarely receive spam through this e-mail address. pgp2e2fJ_RVV9.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] AntiSpam measures circumventing
On 2013-09-20 15:50, Jugurtha Hadjar wrote: I obviously don't like SPAM, but I just thought If I were a spammer, how would I go about it. You wouldn't, it's not effective to do this. You would just grab plain text e-mail addresses and leave it at that, anyone who tries to obfuscate their e-mail address is not worth spamming anyway. pgp6xsHUzQJiW.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Programming Help
On 2013-09-10 21:01, Katie wrote: In my NotePad file, I have the following...I'm not sure if I am even going about doing this problem correctly... I don't envy you having to use notepad. Consider using a more sane editor... you'll thank yourself for it. def sinh(x): return (1/2)*(e^x - e^(-x)) def exp(x): return e**x I am stuck, and don't know where to go from here. I would appreciate help please. You'd have done well to present the problem you're having, but you should know that ^ is XOR (as it is in most programming languages), you probably want ** (and space out your function definitions -- PEP8 says to use two blank lines between functions). pgp_uNjpYYMed.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about Functions
On 2013-09-10 13:34, novo shot wrote: When I declare a variable to be equal as the fucntion (result=theFunction(this either)) is Python also executing the function? You're not declaring it as equal, that would be `==' (or `is' for identity). `=' assigns, it doesn't check for equality. The way I see it, I only called for the function once before printing ARRRGH!! Then after that I declared a variable and then I print. This is how I expected the result to look like: I don't get this reply is: I don't get this either ARRRGH! Why do you expect reply is to happen on the second line? It clearly only happens when printing the returned value, not when printing from inside the function itself: def theFunction(message): print I don't get , message return ARRRGH! theFunction(this) result=theFunction(this either) print reply is: , result The extra spaces are because , implies one. If you don't want a double space before the message, remove the trailing space in the string. pgpLcomPv7jtT.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] cs student needs help import math
On 2013-09-07 17:02, Byron Ruffin wrote: I am writing a simple program based off an ipo chart that I did correctly. I need to use ceil but I keep getting an error saying ceil is not defined. I did import math, I think. I am using 3.2.3 and I imported this way... import math math.pi 3.141592653589793 math.ceil(math.pi) 4 math.floor(math.pi) 3 ... but I get the error when using ceil... pepsticks = ceil(peplength / StickLength) Traceback (most recent call last): File pyshell#19, line 1, in module pepsticks = ceil(peplength / StickLength) NameError: name 'ceil' is not defined The error message is pretty clear, ceil is not defined. If you started by using import math, this is expected, because you need to explicitly call math.ceil, not just ceil. If you want to import ceil into your current namespace, you need to use from: from math import ceil ceil(3.14) 4 pgp0TCLXzzsD9.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A mergesort
On 2013-08-31 22:00, D.V.N.Sarma డి.వి.ఎన్.శర్మ wrote: def merge(a, b): if len(a)*len(b) == 0: return a+b Indentation in Python matters; if you're going to post code, you should probably keep it. We have to look at the statement as v = ((a[0] b[0] and a) or b).pop(0) This is short circuit evaluation, which is fairly common in programming languages.[0] 0: https://en.wikipedia.org/wiki/Short-circuit_evaluation pgpaGypFOdN_q.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to save variables after a user quits in python
On 2013-08-31 14:30, Jack Little wrote: I am coding a game and I want the player to be able to quit the game and immediately take off right from where they started from. If you're asking how to store variables between sessions, look at the pickle module. pgpWT4yz_VlbP.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] myown.getfilesystemencoding()
On 2013-08-30 08:04, Albert-Jan Roskam wrote: In Windows, sys.getfilesystemencoding() returns 'mbcs' (multibyte code system), which doesn't say very much imho. Well, what's the problem you have with mbcs being the output here? On NT, mbcs is the encoding that should be used to convert Unicode to a bytestring that is equivalent when used as a path name, after all. pgpb8pNg4EQeQ.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] os.system() not working
Hello, On 2013-08-27 16:03, Nitish Kunder wrote: I have a python program which i am calling from a php script. The arguments to the program is a path to the file The program when directly run from console executes normally. But when I try to execute the program from browser ie call the python script from php, os.system command is not working what might be the problem. Your question is lacking some context, like Alan already mentioned, but my first suspicions would be: - Relying on a PATH that doesn't exist/is not as you expect in that environment - Relying on a working directory that turns out to not be what you expected pgpYrKxQgRu70.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] os.system() not working
On 2013-08-28 08:16, wolfrage8...@gmail.com wrote: PHP is not Python. You misread. I have a python program which i am calling from a php script. pgpqqKjmHTR5l.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Comment on http://www.catb.org/esr/faqs/smart-questions.html
On 2013-08-27 09:49, Alan Gauld wrote: The reason for preferring shorter lines is to leave room for the chevrons when the message gets quoted multiple times. I always reformat quotes with `gq' in vim when I am quoting, I suggest others do the same. pgp8Ve33ukc7A.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Comment on http://www.catb.org/esr/faqs/smart-questions.html
On 2013-08-27 20:11, Steven D'Aprano wrote: I wish mail clients would support rich text using ReST or Markdown. The mail client could still include a GUI so you choose formatting commands rather than have to type markup. Why can't you do this through your mailcap instead of relying on the client to implement that functionality? Works well enough for me. pgp9_FRLxhvvo.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Resetting state of http.client/httplib HTTPSConnection objects
On 2013-08-26 01:23, Alan Gauld wrote: While this is technically within the remit of this list, since its about a standard library module, I suspect you might be better off asking on the main tutor list. It's at a deeper level of skill/experience than most of the tutor queries. Hm, I guess I don't understand the remit of the two lists then. Tutor has always seemed very... non-tutory. I'll post it there, anyway. Thanks! pgpWZX6Cfnq6n.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] i need help with the following question
On 2013-08-26 01:29, isaac Eric wrote: describe different ways of displaying output using python! Please, read this: http://www.catb.org/esr/faqs/smart-questions.html pgpmEMqlTiuCa.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Comment on http://www.catb.org/esr/faqs/smart-questions.html
On 2013-08-27 12:41, Steven D'Aprano wrote: http://sscce.org/ Keep the width of the lines in your example to under 62 characters wide. I don't really see any reason to use less than 79 in 2013. In my opinion(!), this document is too opinionated to be useful as a generic guide (but it mostly lines up with my own prejudices). If you don't know how to scroll down, I can't help you. There are all sorts of people and places that will teach you the basics of using a web browser, I am not one of them. I have mixed feelings about this. I think this is a poor excuse for poor UX, really. If you are too lazy to read the entire page, you're too lazy to follow whatever instructions we give you, so stop wasting our time. I agree with this one. There's a lot of words to wade thru Writing SMS-speak is not a good way to get ESR to respect your views. (Or mine, for that matter.) Why on earth do people give a crap about thru? It's dictionary approved and peaked in 1930(?) or something, an era when I'm sure if you said they were using SMS speak, they would have laughed in your face. I only give a shit about how someone represents English when it obscures meaning (which I have a hard time believing thru would do). pgpjNv3XEK6Dl.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Resetting state of http.client/httplib HTTPSConnection objects
I am experiencing intermittent issues where an exception will be raised when calling getresponse(), which makes the entire connection stuck in Request-sent state. Is it possible to reset to idle state somehow without reinstantiating the HTTPSConnection? I ideally want to keep the connection to the server, and just reset the state to idle so that I can make another request (like you would usually do by calling getresponse()). a.conn http.client.HTTPSConnection object at 0x7f8d7cb58bd0 a.conn.getresponse() Traceback (most recent call last): File stdin, line 1, in module File /usr/lib64/python3.3/http/client.py, line 1143, in getresponse response.begin() File /usr/lib64/python3.3/http/client.py, line 354, in begin version, status, reason = self._read_status() File /usr/lib64/python3.3/http/client.py, line 324, in _read_status raise BadStatusLine(line) http.client.BadStatusLine: '' a.conn.request(GET, foo) Traceback (most recent call last): File stdin, line 1, in module File /usr/lib64/python3.3/http/client.py, line 1061, in request self._send_request(method, url, body, headers) File /usr/lib64/python3.3/http/client.py, line 1089, in _send_request self.putrequest(method, url, **skips) File /usr/lib64/python3.3/http/client.py, line 944, in putrequest raise CannotSendRequest(self.__state) http.client.CannotSendRequest: Request-sent pgphT9VpQuXQG.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python 3.x VIM
Hi Neelesh, On 2013-08-24 12:55, Neelesh Chandola wrote: On your recommendation , I downloaded VIM but when checking for python 3.x support , using :py3 print (Hello) , it gives error E370 and E263. I also checked :version and it shows that both py2.x and py3.x are in use . So my question is how do I use it just for py3.x .I use win8 . Please help - I am completely new so you would have to explain things while answering . I do not provide any support by 1-to-1 email. If you want support, please e-mail the list (Cc'd to this mail). It sounds like your version of Vim was compiled without Python support, but I haven't used Windows in years, and have no experience in that. As for your question in your followup e-mail, you can find my .vimrc (with all of my other configs) here: https://github.com/cdown/dotfiles Thanks. pgpQXlE2JIlZ0.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How much in a try block?
On 2013-08-23 01:30, Alan Gauld wrote: Unless you really only want g(x) executed if there is no MyError exception but want h(x) executed regardless. I've had that situation a few times before when using the logic try this, or fall back to this if it doesn't work. I'm curious, how often do others use the try/else combination? Rarely. I think I've only used it twice in recent memory. pgpurjbJpvZp9.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] global variables
On 2013-08-22 13:36, Matthew Ngaha wrote: I'm always told to avoid using them. I read discussions on the python irc channel about them but honestly i feel there are some times where i can't avoid using them. Like where i want to keep track of a state variable in many different functions that may or may not alter its value and also not wanting any of the functions to return it to the caller. It sounds like you want to use a class. My question is how many global variables did your last decent sized program have? Also please share any insight you have about them. I do try to avoid them, but is this always possible? I don't have any global variables in any of my projects, and I've been programming Python in some capacity for almost 8 years now. Why would you not just use a class if you want to store state? pgp8g3wmh7NcT.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] global variables
On 2013-08-22 14:43, Matthew Ngaha wrote: I don't feel my program needs a class. Also i have been told to stop using classes by some very experienced Python programmers on irc even though i don't see why. It's confusing being told different things. Well, if you want to store state, you should really be using a class. What has made you think that your program doesn't need a class? There's no need, there's just what's best suited to your problem case (which you have not made clear, so nobody can comment on it). No experienced Python programmers are going to universally tell you not to use classes, likewise, no experienced Python programmers are going to universally tell you to use them all the time. It's a matter of context and suitability, which is entirely dependent on what it is that you are coding in the first place. I would doubt that anyone has told you don't ever use classes, because that's nonsense; you've probably misread a dissuasion from that path in a single instance as applying more broadly than was intended. pgpKOAYswETAY.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] global variables
On 2013-08-22 15:12, Matthew Ngaha wrote: I am being totally honest here. I was very confused at the time and i said i didn't agree because it's what i had put so much effort into learning. They went on to say at some well known Python talks speakers have stated why using OOP (especially inheritance, but not excluding any others) is very bad design and the same thing can always be achieved without it. To be clear they said every use case OOP is the worst option. I asked what about GUIs which their design is strongly based around OOP? and they sad GUIs are badly designed to begin with so it proves the point about OOP. Were these expert Python programmers smoking crack cocaine at the time? pgpQLd06_zYdS.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How much in a try block?
On 2013-08-23 06:20, Amit Saha wrote: On Fri, Aug 23, 2013 at 6:14 AM, leam hall leamh...@gmail.com wrote: If I have a series of tasks that depend on X happening, should I put them all in the same try block or just put X in there and exit out if it fails? You are right about the latter. You should put only the statement which you expect to raise the exception. You can also use the else clause if there is stuff you want to run if the try block doesn't raise the caught exception, which avoids putting it in try if you don't intend to exit from the exception. pgp3aZGkPDAT6.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [OT] Replies go to individuals, not the list?
On 2013-08-21 10:30, Steven D'Aprano wrote: - If there is nowhere I can reasonably trim their comments to establish context, and my response is just a general reply rather than specifically responding to specific comments (e.g. if my reply is thanks for your email, I'll consider it for the future sort of thing) then I might top post, leaving their comments below for context. In such a case, I cut to the conclusion point in their e-mail and reply below it. I don't see why top-posting would be beneficial here, this method is wasteful. pgpE_cCRaj4qE.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Runestone Python Course
On 2013-08-20 21:52, Jim Mooney wrote: This is rather like W3 Schools That doesn't exactly fill me with confidence about the quality of it considering W3Schools is literally the cesspit of web standards misinformation... pgpV6o9SkFJaD.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] library:
On 2013-08-21 13:31, Joel Goldstick wrote: In python libraries are called modules I believe. So you may see either term, and unless someone here corrects me, they are the same. They are often interchangeable, but they do not have to be the same (for example, it is perfectly imaginable that a library contains multiple modules), since library is an aesthetic constraint, but module isn't. pgpuc2BqPHS6p.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] library:
On 2013-08-21 23:30, Alan Gauld wrote: It varies but in general programming terms is a collection of functions or classes that can be reused by programmers. Most languages have a standard library and a collection of additional proprietary libraries. Unless I'm misunderstanding, don't you mean third-party, not proprietary (or is this a use of proprietary that I am not familiar with)? pgp4tuwMQMHTp.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [OT] Replies go to individuals, not the list?
On 2013-08-20 18:40, Andy McKenzie wrote: Well, since someone else brought it up... I really prefer top posting. In general, I don't WANT to reread every message: I want to quickly get to whatever is new. Right, which is why when top posting you should cut to the relevant context. What REALLY gets to me is the people who try to insist that their way is objectively RIGHT, and everyone else is practicing bad habits, or polluting the net, or some other nonsense like that. The fact is, we just have different work flow preferences. You like one thing, I like another. If you want to present your view rationally and objectively, or talk about your preferred layouts, that's fine. But let's not start saying someone has bad habits because they disagree with you. In Gmail (which it appears that you are using) I don't think it really matters, since it selectively collapses the context anyway. It certainly matters when reading in a mail client that doesn't collapse quotes (which, in my opinion, is not something a mail reader should be doing anyway). I agree this is a personal opinion, but mixing the two in a single thread often makes message flow completely incomprehensible. I am also in the bottomposting camp, I'm not very dogmatic about it as long as people don't mix the two in a single thread. Then it just becomes functionally irritating. pgpMSR7KnZqbl.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [OT] Replies go to individuals, not the list?
On 2013-08-21 01:01, Chris Down wrote: Right, which is why when top posting you should cut to the relevant context. s/top posting/bottom posting/ I'm interested to know how you can reply and reference multiple parts of a message clearly when top posting, though. I think that's impossible without destroying clarity. Bottom posting is just objectively much more intuitive when replying per-context and not per-message, which is what you want almost all of the time. pgpkZPPYGkIok.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Error :SyntaxError: 'break' outside loop
On 2013-08-18 10:18, Zoya Tavakkoli wrote: if k == 27: break Well, you're not in a function here, so break doesn't make any sense. What is it that you want to do? pgpYkuuMtY52T.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Error :SyntaxError: 'break' outside loop
On 2013-08-19 10:55, Chris Down wrote: On 2013-08-18 10:18, Zoya Tavakkoli wrote: if k == 27: break Well, you're not in a function here, so break doesn't make any sense. What is it that you want to do? s/function/loop/ pgpV6iNWSeUjo.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] http.server -- stuck at binding [windows8]
Hello, On 2013-08-18 10:40, shanmukhat...@gmail.com wrote: I am developing a simple http media streamer with the help of simple http server of http.server and I have a problem in binding the server. I get the “the address is not valid in it’s content error” and I KNOW that it can be solved by socket.INADDR_ANY but the problem is my router has assigned me 192.168.1.*** and my ISP has given me a ip like 119.*.*.* which is causing the problem.. I find this 119.*.*.* IP nowhere in ipconfig [neither with the /all flag] Your problem is that your computer is behind a NAT provided by your router. Essentially, to provide access to multiple devices on your network while still only using a single external IP address, your router uses network(s) that are private to your LAN and then attempts to map calls from the outside to IPs on the inside. The usual way to handle it would be to bind to your local WAN-facing interface and then port forward on your router, however this is off-topic for this list. This is fairly facile though, if you google for port forward and your router model, you should find instructions on how to do so. Best, Chris pgpRTYYd_LzeW.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Simple Python SNMP ping?
Hi Leam, On 2013-08-14 15:21, leam hall wrote: Is there a way to do a simple check in Python to see if a remote host is listening on SNMP port 161/UDP? Simple in this case could either mean technically simple (in which case, use a socket with SOCK_DGRAM and wait for data) or implementationally simple (in which case, use an SNMP library). I'd only recommend doing the latter. Since UDP is stateless, you'll need to make sure that your destination replies with something, which means you probably need to send a real SNMP request. Since that's the case, you should really just use a real SNMP library (although I fear that your meaning of simple was not using an SNMP library, which is really not simple at all. net-snmp[0] can do this fairly trivially, anyway. The following works for me: import netsnmp var = netsnmp.Varbind('sysDescr.0') netsnmp.snmpget( ... var, ... Version=2, ... DestHost=localhost, ... Community=pub, ... ) ('OpenBSD',) Best, Chris 0: http://www.net-snmp.org/wiki/index.php/Python_Bindings pgpfsJNUJXjPl.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Python-Help] Instancing class issue
Hi Dino, On 2013-08-12 20:32, Dino Bektešević wrote: def __init__(self, **keys): from . import util self.keys=keys self.load() where I don't understand what **keys mean, I've only seen that as **kwargs meaning other key words and arguments in examples. The name of the variable doesn't matter, that's still what it does; you can think of it as encapsulating any other keyword arguments. def foo(bar, **kwargs): ... print(bar: %s % (bar,)) ... print(kwargs: %r % (kwargs,)) ... foo(bar, baz=qux, wibble=wobble) bar: bar kwargs: {'baz': 'qux', 'wibble': 'wobble'} When I try to instance Astrom class by: new=Astrom() I receive a following error: Sorry, no idea about this bit, I've never used sdsspy. est of luck sorting this out. Chris pgpR9GydIB2YX.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Map function
Hi Phil, On 2013-08-10 16:45, Phil wrote: The Arduino has a map function named map which looks like this: map(value, 0, 1023, 0, 100) The function, in this case, takes an integer value between 0 and 1023 and returns a number between 0 and 100. Is there a Python equivalent? The Arduino documentation[0] says that `map' is equivalent to: long map(long x, long in_min, long in_max, long out_min, long out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } With that in mind, you can almost copy and paste the exact same code in Python (albeit with floor division, as in Python 3, integer division can yield floats). Note that `//' is not strictly equivalent to C's integer division, though.[1] def arduino_map(x, in_min, in_max, out_min, out_max): ... return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min ... arduino_map(50, 0, 1023, 0, 100) 4 0: http://arduino.cc/en/Reference/map 1: http://stackoverflow.com/a/5365702/945780 pgpDNN5Xo52jH.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Start multiple threads from Python
On 2013-08-05 12:17, Ryan Waples wrote: Currently I am calling each analysis program one at a time with subprocess.call(). This is working without a hitch, but as each analysis can take a while to run, I want to try to speed things up. I realize I can start three different python sessions to do this, but that just begs the question how to do that from python? subprocess.Popen does not block unless you explicitly tell it to (by using communicate()). Perhaps that's what you want. import subprocess x = subprocess.Popen([ sleep, 60 ]) y = subprocess.Popen([ sleep, 60 ]) x.pid 3035 y.pid 3036 pgp7_7NXZ0dcW.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] adding users to tweets on a list
On 2013-08-06 18:36, Dave Angel wrote: This version should be a bit cleaner than what I've seen on this thread. Our methods are almost the same, other than the fact that you don't use a generator, and you do the length validity check during the loop instead of preemptively, I'm not sure which I think is cleaner. I'm more inclined toward using more lines of code to clearly express the reason for the failure's conclusion, but either is perfectly valid and readable. Thanks for the alternative :-) On 2013-08-06 18:36, Dave Angel wrote: BTW, you have a bunch of other messages on the thread which are replying to the invisible man, posts that aren't (yet?) visible. Since you quote him without attribution, we have no clue who you're commenting about. He is replying to me, but his client seems to not prepend any header to his quotes. I am new to this list and am still held in the moderation queue. Chris pgpDLqAd47rSw.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] adding users to tweets on a list
On 2013-08-06 03:48, Saad Javed wrote: I want to add users to the tweet from the list, the no. of users added based on the length of the tweet. It looks like you're using Python 2, but you didn't specify. I'd probably do something like this: #!/usr/bin/env python MAX_LENGTH = 140 users = [ saad, asad, sherry, danny, ali, hasan, adil, yousaf, maria, bilal, owais, ] def populate(): message = raw_input(Enter string: ) while users: new_message = .join([message, @ + users.pop(0)]) if len(new_message) MAX_LENGTH: break message = new_message return message if __name__ == __main__: print(populate()) pgpOYYsWsbV6Z.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] adding users to tweets on a list
On 2013-08-06 19:42, Chris Down wrote: All that needs to happen is to move the pop to the top of the MAX_LENGTH check: while len(new_message) + len(add) = MAX_LENGTH: ...or, better, remove the if...break and just do: while users and len(new_message) + len(add) = MAX_LENGTH: pgpWu6B0bGjbi.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] adding users to tweets on a list
On 2013-08-06 14:40, Saad Javed wrote: It will add max no. of users to one tweet until limit is reached. I want all users added to the tweet. E.g. if 4 users can be added to the tweet before reaching the limit, return three tweets...first two with 4 users attached and the last one with three. Ah, I see. Sorry, I misread your requirements. Something like this should work. #!/usr/bin/env python MAX_LENGTH = 140 class TweetTooLongError(Exception): Raised when a user would be too long to add to the tweet, even alone. pass def generate_tweets(message, users): Generate tweets based around a message, with users appended to each tweet. :param message: the base message :param users: a group of users to append :returns: tweets based around the message to the users add = longest_in_list = @ + max(users, key=len) if len(longest_in_list) + len(message) MAX_LENGTH: raise TweetTooLongError( At least one user would make the tweet too long. ) while users: new_message = message while len(new_message) + len(add) = MAX_LENGTH: new_message += add if not users: break add = @ + users.pop(0) yield new_message if __name__ == __main__: users = [ saad, asad, sherry, danny, ali, hasan, adil, yousaf, maria, bilal, owais, ] message = raw_input(Enter string: ) print(\n.join(generate_tweets(message, users))) pgpCWLSHd9g2t.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] adding users to tweets on a list
On 2013-08-06 22:31, Saad Javed wrote: Thank you for your response. This code has a bug. If there is one user left in the user list, it doesn't print a tweet with just that one user added. For example use this string: These are my friends living in the same city as i am. I have known them for years. They are good people in general. They are:...you will see that owais is still in the list and is not added to a new tweet and printed. Good catch, that's my bad, sorry. Because pop() is called on the last element just before the next iteration, when `users' is coerced to a bool, it becomes False in the outer while loop. This affects only 50% of cases because it's possible we will be in the inner loop when we hit the last element in `users', which is why I didn't see it. All that needs to happen is to move the pop to the top of the MAX_LENGTH check: while len(new_message) + len(add) = MAX_LENGTH: add = @ + users.pop(0) new_message += add if not users: break pgpJ22_EEMAoB.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] adding users to tweets on a list
On 2013-08-06 22:49, Saad Javed wrote: That causes: Enter string: These are my friends living in the same city as i am. I have known them for years. They are good people in general. They are: Traceback (most recent call last): File chris_tweet_len.py, line 44, in module print(\n.join(generate_tweets(message, users))) File chris_tweet_len.py, line 31, in generate_tweets while users and len(new_message) + len(add) = MAX_LENGTH: UnboundLocalError: local variable 'new_message' referenced before assignment Cannot reproduce. I'm not sure how you edited the script, but somehow you moved new_message to where it is unbound. See attached. And the earlier fix now adds two users to a tweet, then one user, then two user, then one... :( I don't see how that differs from your expected output...? I want all users added to the tweet. E.g. if 4 users can be added to the tweet before reaching the limit, return three tweets...first two with 4 users attached and the last one with three. You hit the 140 character limit if another user is added, so it resets to the base message and adds the next user(s) as possible. What is your expected output for that sample input? #!/usr/bin/env python MAX_LENGTH = 140 class TweetTooLongError(Exception): Raised when a user would be too long to add to the tweet, even alone. pass def generate_tweets(message, users): Generate tweets based around a message, with users appended to each tweet. :param message: the base message :param users: a group of users to append :returns: tweets based around the message to the users add = longest_in_list = @ + max(users, key=len) if len(longest_in_list) + len(message) MAX_LENGTH: raise TweetTooLongError( At least one user would make the tweet too long. ) while users: new_message = message while users and len(new_message) + len(add) = MAX_LENGTH: add = @ + users.pop(0) new_message += add yield new_message if __name__ == __main__: users = [ saad, asad, sherry, danny, ali, hasan, adil, yousaf, maria, bilal, owais, ] message = raw_input(Enter string: ) print(\n.join(generate_tweets(message, users))) pgpgSwyxathrA.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor