|
I'm running Mac OS X Tiger, and Python 2.5, and I wanted to update my PYTHONPATH to permanently look in a scripts folder, so I typed into Terminal:code:
code:
|
# ? Dec 18, 2008 08:54 |
|
|
# ? May 14, 2024 16:08 |
|
^^^ Try typing 'python2.5' and see if that brings anything up. It's probably in /Library/Frameworks/Python.framework/Versions/2.5/bin, which you should add to your $PATH ahead of everything else. Also, since it sounds like you're an admin on the computer, you should instead add a .pth file to your site-packages folder instead of using $PYTHONPATH. You'll be able to see the directory always, instead of just with the right mix of environment variables. Does .profile exist? That could be what was adding the aforementioned directory to $PATH previously. IntoTheNihil posted:I literally just (an hour ago) jumped into programming with Python. Right now i'm using this and am up to the 5th part. I'm understanding it so far but I'm not holding much in my memory. Is there a better online tutorial or even book I should use or is this just normal confusion that goes away after using Python for a few weeks. I've seen that tutorial before, and while it's okay for the most part, it explains things badly. Think Python is great for new programmers, and if you want to read another tutorial after that, the official tutorial is also pretty good. Dive Into Python is behind the times, being written for python 2.2, as well as not as clear as other tutorials I've seen. I think its only strong point is that it covers more of the standard library. Think Python and the official tutorial cover some of the shiny new things that have been added to the language since. Habnabit fucked around with this message at 09:02 on Dec 18, 2008 |
# ? Dec 18, 2008 08:57 |
|
It seems that just running python2.5 caused it to unfuck itself, because when I opened .bash_profile, the proper Python path was in there. I removed the /Users/latexenthusiast/python/scripts from my PYTHONPATH and used the .pth file instead. I was kind of unsure where my site-packages were before this, but in the process of searching for Python 2.5 earlier, I found it, so now I know how to properly use those. After restarting Terminal, everything seems to be in order. Thank you so much for your help! I was expecting to have to wait quite a bit longer for a proper response, but people like you make this place worth .
|
# ? Dec 18, 2008 09:12 |
|
If you're like me, you know that computer programs aren't really doing anything unless the computer's beeping. After discovering this code:
I now have the basis for adding random beeps to be played during any, and all, loops. I hope this helps someone else. chemosh6969 fucked around with this message at 22:45 on Dec 22, 2008 |
# ? Dec 18, 2008 22:36 |
|
EDIT: Nevermind, I got it up and running. UnNethertrash fucked around with this message at 07:59 on Dec 20, 2008 |
# ? Dec 20, 2008 00:49 |
|
Alright, I'm not having a problem per-se, but I'm sure that the way I'm going about this program is inefficient. Here's what I've got so far.code:
|
# ? Dec 21, 2008 03:22 |
|
I'm not so hot on music theory, but maybe you could do something like this:code:
code:
code:
code:
Also I don't think there's much point in putting this into a function, because it doesn't take any parameters or return anything, it just does input and output, so that's better suited to just be in the top level code of the module. hey mom its 420 fucked around with this message at 04:12 on Dec 21, 2008 |
# ? Dec 21, 2008 04:00 |
|
That looks great! Thanks a ton. I knew there had to be some way to do it. Edit: Works perfectly so far! Thank you. Plastic Snake fucked around with this message at 08:08 on Dec 21, 2008 |
# ? Dec 21, 2008 06:49 |
|
That big ben song is hilarious.
|
# ? Dec 22, 2008 17:59 |
|
Kire posted:That big ben song is hilarious. What on earth are you talking about
|
# ? Dec 22, 2008 18:57 |
|
m0nk3yz posted:What on earth are you talking about Above, the code example plays "big ben".
|
# ? Dec 22, 2008 19:21 |
Silly question. The following code always returns a 400 error. Seems the request/header information sent to the headers isn't right. It's using the built in HTML/HTTP library, so I think I'm using it wrong. What's the issue? Python 3k code:
|
|
# ? Dec 22, 2008 19:30 |
|
host=website, post=80 I assume that should be port
|
# ? Dec 22, 2008 19:46 |
|
Anyone know a module that does MIME decoding for email? I'm working on an app that is reading messages from a POP3 server and just need the from address, subject, and body of the message. Unfortunately email I've found some email clients (Blackberries, Outlook) do loving horrible things to email. I just need a way to reliably extract plain text from the email.
|
# ? Dec 23, 2008 03:16 |
|
ATLbeer posted:Anyone know a module that does MIME decoding for email?
|
# ? Dec 23, 2008 03:29 |
|
No Safe Word posted:Does the one that comes in the standard lib not cut it? Or was it just overlooked? It didn't cut it for some reason. Maybe I was misusing it but, it for some cases (BB email in particular) would just pass back the plain encoded text. I'm using poplib to retrieve the email and tried passing it to the email lib. Maybe I'm just using it wrong.
|
# ? Dec 23, 2008 03:41 |
|
ATLbeer posted:It didn't cut it for some reason. Maybe I was misusing it but, it for some cases (BB email in particular) would just pass back the plain encoded text. I'm not 100% sure, but I was doing a similar thing and asked a question here and I may have pasted the code I was trying. If not, I'll link to the guide I was working off of. My problem was the body of the email. I could get it but it was one big blob that I couldn't do anything with. I couldn't get a single word out of the thing. I tried converting it to strings, using indexes, and other stuff I can't remember and I couldn't get anywhere with that thing. The entire thing would shoot out of whatever blender I was trying to chop it up in and then it would laugh at me. If you're able to do anything with the body you're getting, could show me how you did it?
|
# ? Dec 23, 2008 03:54 |
|
chemosh6969 posted:I'm not 100% sure, but I was doing a similar thing and asked a question here and I may have pasted the code I was trying. This is the exact problem I'm having
|
# ? Dec 23, 2008 05:09 |
|
ATLbeer posted:This is the exact problem I'm having http://stackoverflow.com/questions/315362/properly-formatted-example-for-python-imap-email-access#316457 This example died on me at the end but when combined with the knowledge from http://www.devshed.com/c/a/Python/Python-Email-Libraries-part-2-IMAP/ I was able to get an email into the data variable of the first link. data[0][1] will return it as a string. edit: Then you'll have a string with a bunch of /r/n After a quick twist(if you don't want them)... code:
It's not pretty but it's a start. chemosh6969 fucked around with this message at 22:36 on Dec 23, 2008 |
# ? Dec 23, 2008 18:59 |
|
On Windows XP I'm trying to get the output from a command using the subprocess module in Python 3.0 The subprocess docs say this: output=`mycmd myarg` ==> output = Popen(["mycmd", "myarg"], stdout=PIPE).communicate()[0] So I try it: >>> output = subprocess.Popen(["a.bat"], stdout=PIPE).communicate()[0] Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'PIPE' is not defined I then tried getoutput: >>> subprocess.getoutput("a.bat") "'{' is not recognized as an internal or external command,\noperable program or batch file." What's going on? How do you guys get the output from a command back into Python? Thanks.
|
# ? Dec 25, 2008 20:57 |
|
code:
|
# ? Dec 25, 2008 21:45 |
|
dwayne_dibbley posted:>>> output = subprocess.Popen(["a.bat"], stdout=PIPE).communicate()[0] Looks like a typo in the docs: try stdout=subprocess.PIPE
|
# ? Dec 25, 2008 22:01 |
|
nbv4 posted:a "can't compare date and datetime objects" on the last line. Whats going on here? date and datetime are seperate objects, date doesn't include a time, and datetime does. helpful, eh? from the python docs quote:In other words, date1 < date2 if and only if date1.toordinal() < date2.toordinal(). In order to stop comparison from falling back to the default scheme of comparing object addresses, date comparison normally raises TypeError if the other comparand isn’t also a date object. However, NotImplemented is returned instead if the other comparand has a timetuple() attribute. This hook gives other kinds of date objects a chance at implementing mixed-type comparison. If not, when a date object is compared to an object of a different type, TypeError is raised unless the comparison is == or !=. The latter cases return False or True, respectively. I would assume that the reason you can't compare date and datetimes, is that the start time of a date can vary from culture to culture.
|
# ? Dec 25, 2008 22:10 |
|
Janin posted:Looks like a typo in the docs: try stdout=subprocess.PIPE Unfortunately no dice... >>> output = subprocess.Popen(["a.bat"], stdout=subprocess.PIPE).communicate()[0] Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'subprocess' is not defined
|
# ? Dec 25, 2008 22:24 |
|
Is this your first time using Python? You will have to import the subprocess module before it may be used.
|
# ? Dec 25, 2008 22:30 |
|
Thanks. Dammit how can I forget to import. Yeah, these are my first few hours using Python. Mmmm... so what I get back is a big bunch of bytes/characters. I was hoping for something easier to deal with. Back to the drawing board.
|
# ? Dec 25, 2008 22:50 |
|
dwayne_dibbley posted:Thanks. What kind of bytes/characters? What are you expecting the output to be? Python has functionality for switching between character encodings if that's the problem.
|
# ? Dec 26, 2008 02:07 |
|
nbv4 posted:This function determines whether or not you were forty years old when you had an exam. When I open a python shell, the code works fine, but when I use it in my application, I get an error saying "global name date is not defined" (or something to that effect, i'm writing this post from a different computer) on the line where fortieth_birthday is defined. Whats weird is that if I change "datetime.date(..." to datetime.datetime(..." is works, but gives me a "can't compare date and datetime objects" on the last line. Whats going on here? If you're getting a NameError saying "global name 'date' not defined" then you're not doing "datetime.date". Seeing the full traceback would definitely help here. See also: datetime.date.replace.
|
# ? Dec 26, 2008 02:30 |
|
Habnabit posted:If you're getting a NameError saying "global name 'date' not defined" then you're not doing "datetime.date". Seeing the full traceback would definitely help here. See also: datetime.date.replace. actually the problem was when I had datetime.date, the function would execute correctly, and the error was being thrown from within another function. I assumed changing "datetime" to "date" would be the cause of that error. My dumb rear end didn't read the line number of the error
|
# ? Dec 26, 2008 04:25 |
|
hey guys, here is a really simple question. when i am trying to use IDLE, i cant use nested elif statements. for example, x=2 if x==1: print(x) *there should be a tab in this line but for some reason its not showing up in the post elif x==2: print(x) else: print(x) that generates an error, does anyone have any idea why? awesomepanda fucked around with this message at 07:28 on Dec 26, 2008 |
# ? Dec 26, 2008 07:22 |
|
sorry for the double post.
|
# ? Dec 26, 2008 07:22 |
|
CrazyPanda posted:
The above code works fine provided the whitespace is where it should be.
|
# ? Dec 26, 2008 10:34 |
|
tripwire posted:What kind of bytes/characters? What are you expecting the output to be? Python has functionality for switching between character encodings if that's the problem. I've just starting learning Python and my current learning target is to use the logging module to make one nice logfile for everything my script does. So I want to get the output of external commands run in my script and shove them into the logfile. a.bat: @echo off echo Output from external command line 1 echo Output from external command line 2 >>> output = subprocess.Popen("a.bat", stdout=subprocess.PIPE).communicate()[0] >>> print(output) b'Output from external command line 1\r\nOutput from external command line 2\r\n' I guess I can do this but the output is not tidy: >>> for i in str(output).split("\\r\\n"): ... print(i) b'Output from external command line 1 Output from external command line 2 ' Looking around the docs I found this: >>> output=os.popen("a.bat") >>> for i in output.readlines(): ... print(i) ... Output from external command line 1 Output from external command line 2 Apart from the extra blank lines this is what I need so I can go with this. It seems the subprocess module is the 'proper' way to do this but I can't get it to work nicely...
|
# ? Dec 26, 2008 12:17 |
|
dwayne_dibbley posted:>>> print(output) quote:As the str and bytes types cannot be mixed, you must always explicitly convert between them. Use str.encode() to go from str to bytes, and bytes.decode() to go from bytes to str. You can also use bytes(s, encoding=...) and str(b, encoding=...), respectively. code:
code:
dwayne_dibbley posted:>>> output=os.popen("a.bat") ChiralCondensate fucked around with this message at 14:42 on Dec 26, 2008 |
# ? Dec 26, 2008 14:32 |
|
ChiralCondensate posted:Did you try calling split() directly on the bytes object? (I don't know if it has such a method.) TypeError: Type str doesn't support the buffer API ChiralCondensate posted:
Aaaahaaaa! That's what I wanted! Thanks! (Now I'll read up on this encoding/decoding stuff.)
|
# ? Dec 26, 2008 15:59 |
|
You can also use str.splitlines, or keep your Popen object around and iterate over its stdout attribute or call readlines on the stdout attribute.
|
# ? Dec 26, 2008 21:05 |
Lord Uffenham posted:host=website, post=80 Yes. It's working now. Thank you so much.
|
|
# ? Dec 27, 2008 10:16 |
|
I'm trying to write a simple script that solves:code:
code:
It's hard to explain but with the print commands it's pretty clear, if you run it, that the list 'numbers' gets smaller even though I never remove anything from it. It's got to be some stupid little mistake, but I can't seem to figure it out. a = 2, d = 1, e = 6, f = 3, g = 7, i = 8, o = 4, p = 0, r = 5, u = 9 I did it by hand first, then bet myself I could do it faster on python. I would greatly appreciate any help. Thanks.
|
# ? Dec 28, 2008 08:51 |
|
UnNethertrash posted:It's hard to explain but with the print commands it's pretty clear, if you run it, that the list 'numbers' gets smaller even though I never remove anything from it. It's got to be some stupid little mistake, but I can't seem to figure it out. code:
|
# ? Dec 28, 2008 11:58 |
|
|
# ? May 14, 2024 16:08 |
|
In Django, you can format dates in the template system by using PHP-style date format strings like so: "{{ my_date|"n-j-Y" }}" but how do you do the same thing from within python itself? I know about datetime.date.strftime() and strptime(), but those functions take a completely different date formatting "language"...
|
# ? Dec 28, 2008 18:11 |