Re: How to import Wave files into python?
How exactly do I import a .wav file and run it? also is it possible to run it inside a while loop if so or it just start playing when its run? - Tom 14 -- For the GUI (Tkinter) there is tkSnack. If you want to run it from the command line you could use sox. -- https://mail.python.org/mailman/listinfo/python-list
Re: why can't download file from linux server into local window disk c:?
with open(localpath, 'wb') as fl: PermissionError: [Errno 13] Permission denied: 'c:' I remember gloomily (haven't used windows since ages) that newer Windows versions don't like users to write directly to C:. Have you tried to save the file to your Documents folder? Regards, Alba -- https://mail.python.org/mailman/listinfo/python-list
Re: why can't download file from linux server into local window disk =?
> with open(localpath, 'wb') as fl: > PermissionError: [Errno 13] Permission denied: 'c:' I remember gloomily (haven't used windows since ages) that newer Windows versions don't like users to write directly to C:. Have you tried to save the file to your Documents folder? Regards, Alba --- SoupGate-Win32 v1.05 * Origin: nntp.gatew...@.piz.noip.me> (1:249/999) --- Synchronet 3.15b-Win32 NewsLink 1.92 SpaceSST BBS Usenet <> Fidonet Gateway -- https://mail.python.org/mailman/listinfo/python-list
Dictionaries
Hi, This might sound weird, but is there a limit how many dictionaries a can create/use in a single script? My reason for asking is I split a 2-column-csv (phone#, ref#) file into a dict and am trying to put duplicated phone numbers with different ref numbers into new dictionaries. The script deducts the duplicated 46 numbers but it only creates batch1.csv. Since I obviously can't see the wood for the trees here, can someone pls punch me into the right direction ...(No has_key is fine, its python 2.7) f = open("file.csv", 'r') myDict = {} Batch1 = {} Batch2 = {} Batch3 = {} for line in f: if line.startswith('Number' ): print "First line ignored..." else: k, v = line.split(',') myDict[k] = v f.close() for k, v in myDict.items(): if Batch1.has_key(k): if k in Batch2.has_key(k): Batch3[k] = v else: Batch2[k] = v else: Batch1[k] = v for k, v in Batch1.items(): newLine = "%s,%s" % (k, v) with open("batch1.csv", "a") as f: f.write(newLine) for k, v in Batch2.items(): newLine = "%s,%s" % (k, v) with open("batch2.csv", "a") as f: f.write(newLine) for k, v in Batch3.items(): newLine = "%s,%s" % (k, v) with open("batch3.csv", "a") as f: f.write(newLine) -- https://mail.python.org/mailman/listinfo/python-list
Re: Dictionaries
Thanks Peter for the fast response, but the prob is solved. My colleague just verbally slapped me because a dict SHOULDN'T have duplicate keys... I change it around to duplicate values and it works fine I think I need coffee now... lots of it. -- https://mail.python.org/mailman/listinfo/python-list
Re: Script that converts between indentation and curly braces in Python code
from __future__ import braces is just an easter egg... ...and shouldn't it better state from __past__ import braces ;-) Anyway, as far as I know the IPython interpreter can recognize lines ending in ‘:’ and indent the next line, while also un-indenting automatically after ‘raise’ or ‘return’. => sas -- http://mail.python.org/mailman/listinfo/python-list
Re: Best Python book(s) for a pre-teen?
Am 01.08.2013 14:11, schrieb beliav...@aol.com: On Tuesday, February 18, 2003 2:27:58 PM UTC-5, Mike Silva wrote: Hi all, My son is 11 and wants to try programming, partly because it's what I do for a living. Even though I don't (yet?) use or even know Python, through some unexplainable thought process I've decided it would be a good language to start him off with. The Art of Problem Solving site, geared toward the best U.S. junior high and high school math students, offers a 10-week "Introduction to Programming" class http://www.artofproblemsolving.com/School/classlist.php that uses Python. There are weekly lectures in an online classroom and graded homework assignments. My 10yo boy is taking the class. But he tells me JavaScript is his favorite language :). I would have a look at this one: http://www.cosc.canterbury.ac.nz/csclub/book.pdf. If you like it you can still buy the print version. sas -- http://mail.python.org/mailman/listinfo/python-list
Re: Using sudo to write to a file as root from a script
Am 09.08.2013 05:47, schrieb David: On 9 August 2013 14:11, Adam Mercer wrote: I'm trying to write a script that writes some content to a file root through sudo, but it's not working at all. I am using: [...] At a quick glance, I have a couple of suggestions. command = ['echo', '-n', channel, '|', 'sudo', 'tee', config_file] sudo doesn't work like this. It doesn't read from standard input. You need to supply the command as an argument to sudo. Get the sudo syntax correct by learning to use it in a shell (eg terminal running bash ) before trying to use it from python code. Also, I think that passing the pipe character '|' as an argument to Popen is not the correct way to use pipes. So, if you figure out how to use sudo without '|' you will solve both these issues. Or try to change the permissions os.system("chmod 666 config_file) do what you want with the file and set the permissions back to their original state. -- http://mail.python.org/mailman/listinfo/python-list
Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of
[Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] Error in sys.excepthook: [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] ValueError: underlying buffer has been detached [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] Original exception was: [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] Traceback (most recent call last): [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] File "/home/nikos/public_html/cgi-bin/metrites.py", line 169, in [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] cur.execute('''SELECT ID FROM counters WHERE url = %s''', page ) [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] File "/usr/local/bin/python/lib/python3.3/site-packages/pymysql/cursors.py", line 108, in execute [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] query = query % escaped_args [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] TypeError: unsupported operand type(s) for %: 'bytes' and 'str' I quote from a Python 3 Guide [http://python.about.com/od/python30/ss/30_strings_3.htm]: The two data types, str and bytes, are mutually exclusive. One cannot legally combine them into one call. With the distinction between text and data, therefore, comes the need to convert between them. -- http://mail.python.org/mailman/listinfo/python-list
Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of
Am 27.08.2013 16:04, schrieb Ferrous Cranus: Στις 27/8/2013 4:59 μμ, ο/η ishish έγραψε: [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] Error in sys.excepthook: [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] ValueError: underlying buffer has been detached [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] Original exception was: [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] Traceback (most recent call last): [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] File "/home/nikos/public_html/cgi-bin/metrites.py", line 169, in [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] cur.execute('''SELECT ID FROM counters WHERE url = %s''', page ) [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] File "/usr/local/bin/python/lib/python3.3/site-packages/pymysql/cursors.py", line 108, in execute [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] query = query % escaped_args [Tue Aug 27 13:02:57 2013] [error] [client 110.202.175.189] TypeError: unsupported operand type(s) for %: 'bytes' and 'str' I quote from a Python 3 Guide [http://python.about.com/od/python30/ss/30_strings_3.htm]: The two data types, str and bytes, are mutually exclusive. One cannot legally combine them into one call. With the distinction between text and data, therefore, comes the need to convert between them. So, in this line: cur.execute('''SELECT ID FROM counters WHERE url = %s''', page ) the variable 'page' needs conversion to what? all that is stores is the location of a file path = '/home/nikos/public_html/' page = form.getvalue('page') if not page and os.path.exists( file ): # it is an html template page = file.replace( path, '' ) So chnage it to what? -- What is now proved was at first only imagined! The error occurs in file "/usr/local/bin/python/lib/python3.3/site-packages/pymysql/cursors.py", line 108, in execute query = query % escaped_args You can check the actual values and data types using: print repr(query) print type(query) print repr(escaped_args) print type(escaped_args) Always useful is a proper exception handling using try:/except: -- http://mail.python.org/mailman/listinfo/python-list
Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of
Am 28.08.2013 10:48, schrieb Ferrous Cranus: >> I quote from a Python 3 Guide >> [http://python.about.com/od/python30/ss/30_strings_3.htm]: >> >> The two data types, str and bytes, are mutually exclusive. One >> cannot >> legally combine them into one call. With the distinction between >> text >> and data, therefore, comes the need to convert between them. >> >> > > So, in this line: > > cur.execute('''SELECT ID FROM counters WHERE url = %s''', page ) > > the variable 'page' needs conversion to what? > > all that is stores is the location of a file > > path = '/home/nikos/public_html/' > > page = form.getvalue('page') > > if not page and os.path.exists( file ): > # it is an html template > page = file.replace( path, '' ) > > So chnage it to what? > -- > What is now proved was at first only imagined! The error occurs in file "/usr/local/bin/python/lib/python3.3/site-packages/pymysql/cursors.py", line 108, in execute query = query % escaped_args You can check the actual values and data types using: print repr(query) print type(query) print repr(escaped_args) print type(escaped_args) Always useful is a proper exception handling using try:/except: hOW YOU MEAN PLEASE I TRY TO IMPLMENT WHAT YOU PROPOSE BUT I CANT. try: #find the needed counter for the page URL if os.path.exists( path + page ) or os.path.exists( cgi_path + page ): cur.execute('''SELECT ID FROM counters WHERE url = %s''', page ) data = cur.fetchone() #URL is unique, so should only be one print repr('''SELECT ID FROM counters WHERE url = %s''') print type('''SELECT ID FROM counters WHERE url = %s''') print repr(escaped_args) print type(escaped_args) I MEAN IF FAILS BEFORE IT TRIES TO GO INTO MY PRINT STAEMNT. HOW AM I GONNA CPATURE THE QUERY? http://i.stack.imgur.com/jiFfM.jpg http://wiki.python.org/moin/HandlingExceptions -- http://mail.python.org/mailman/listinfo/python-list
Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of
Am 28.08.2013 12:14, schrieb Ferrous Cranus: Okey, continue trying and trying i came up with this: try: if os.path.exists( path + page ) or os.path.exists( cgi_path + page ): cur.execute('''SELECT ID FROM counters WHERE url = %s''', page ) data = cur.fetchone() except: with open("err.out", "a") as f: f.write( repr(query), type(query) ) f.write( repr(escaped_args), type(escaped_args) ) But i cannot test it without looking at the error log which is scrolling like hell and doesn't even quit with a ctrl+c How will i manage to troubleshoot? Please confirm the above is correct and is what you were propsoing i shoudl test. A simple way I always use if it comes to exception handling: import sys import traceback # Exception Identification def formatExceptionInfo(maxTBlevel=5): cla, exc, trbk = sys.exc_info() excName = cla.__name__ try: excArgs = exc.__dict__["args"] except KeyError: excArgs = "" excTb = traceback.format_tb(trbk, maxTBlevel) return (excName, excArgs, excTb) try: # Your code except: print formatExceptionInfo() -- http://mail.python.org/mailman/listinfo/python-list
Re: [error] [client 178.59.111.223] (2)No such file or directory: exec of
Well there you have it: File "/home/nikos/public_html/cgi-bin/metrites.py", line 191, in if not data: NameError: name 'data' is not defined -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a function that applies list of functions to a value?
Am 28.08.2013 13:52, schrieb AdamKal: Hi, From time to time I have to apply a series of functions to a value in such a way: func4(func3(func2(func1(myval I was wondering if there is a function in standard library that would take a list of functions and a initial value and do the above like this: func_im_looking_for([func1, func2, func3, func4], myval) I looked in itertools but nothing seamed to do the job. This seams like something vary obvious that was needed many times elsewhere so maybe you could help me? You could try somthing like: myval = 'whatever' for i in range(1,4): print eval("func%s(%s)" % (i, myval)) -- http://mail.python.org/mailman/listinfo/python-list
Re: [RELEASED] Python 3.4.0a2
Am 09.09.2013 13:02, schrieb Larry Hastings: To download Python 3.4.0a2 visit: http://www.python.org/download/releases/3.4.0/ [quote] Python 3.4.0 alpha 2 was released on September 10th, 2013... [/quote] Import from __future__ ?? ;-) -- https://mail.python.org/mailman/listinfo/python-list
Re: I haev fixed it
Am 01.10.2013 13:25, schrieb Νίκος: Στις 1/10/2013 3:21 μμ, ο/η Νίκος έγραψε: Στις 1/10/2013 3:12 μμ, ο/η Heiko Wundram έγραψε: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Am 01.10.2013 14:06, schrieb Νίκος: i know about the link you mentioned and i have deleted the source code from there. Guess what: Google keeps a cache. See here: http://webcache.googleusercontent.com/search?q=cache:http://superhost.gr/~dauwin/cgi-bin/metrites.py So if you haven't changed your password(s), you'd better do that now. Tahnk you Heiko i didnt knew Google was keeping cached version of files. But i have deleted the file metrites.py 2 days ago when i saw Mark Lawrence mentioned it and i also have changed the passwords from my personal account and root as well. I know how he did it, he sees it form here: http://superhost.gr/~nikos/cgi-bin/metrites.py I must somehow use an apache directive not to allow such view. I agree. Just keep folders for scripts and templates above the actual public_html. Sas -- https://mail.python.org/mailman/listinfo/python-list
Re: I haev fixed it
Am 01.10.2013 14:14, schrieb Νίκος: Στις 1/10/2013 3:50 μμ, ο/η ishish έγραψε: Am 01.10.2013 13:25, schrieb Νίκος: Στις 1/10/2013 3:21 μμ, ο/η Νίκος έγραψε: Στις 1/10/2013 3:12 μμ, ο/η Heiko Wundram έγραψε: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Am 01.10.2013 14:06, schrieb Νίκος: i know about the link you mentioned and i have deleted the source code from there. Guess what: Google keeps a cache. See here: http://webcache.googleusercontent.com/search?q=cache:http://superhost.gr/~dauwin/cgi-bin/metrites.py So if you haven't changed your password(s), you'd better do that now. Tahnk you Heiko i didnt knew Google was keeping cached version of files. But i have deleted the file metrites.py 2 days ago when i saw Mark Lawrence mentioned it and i also have changed the passwords from my personal account and root as well. I know how he did it, he sees it form here: http://superhost.gr/~nikos/cgi-bin/metrites.py I must somehow use an apache directive not to allow such view. I agree. Just keep folders for scripts and templates above the actual public_html. python scripts need to be placed inside the 'cgi-bin/' folder which is located at '~/public_html/'. Othwerise they wont work. That's due to your (or whoever set these up) configurations. I have never used the public_html to store perl, python or php scripts and it works perfectly fine for me. Sas -- https://mail.python.org/mailman/listinfo/python-list
Re: JUST GOT HACKED
Am 02.10.2013 13:47, schrieb Chris “Kwpolska” Warrick: On Wed, Oct 2, 2013 at 1:48 AM, Tim Delaney wrote: On 2 October 2013 09:28, Νίκος wrote: con = pymysql.connect( db = 'mypass', user = 'myuser', passwd = 'mysqlpass', charset = 'utf8', host = 'localhost' ) That was viewable by the link Mark have posted. But this wasnt my personal's account's login password, that was just the mysql password. Mysql pass != account's password Because there's no chance with the brilliance you display that there could be any possibility of login details being kept in plaintext in your database. Or the statement is a blatant lie and was meant to be mysql_password is not account_password as they have the same value, but are set independently. (too much Python Ale…) Who cares... mysql> \! bash... job done. -- https://mail.python.org/mailman/listinfo/python-list
Re: Can arbitrary code run in a server if someone's know just the MySQL password?
Am 02.10.2013 15:46, schrieb Νίκος: But i need to know what happened and how this .html file got uploaded. This is not a python question, but this happened from this pythons NG. ... ... Who says that?? -- https://mail.python.org/mailman/listinfo/python-list
Re: Sexism in the Ruby community: how does the Python community manage it?
Am 17.10.2013 18:16, schrieb Roy Smith: On Thursday, October 17, 2013 11:07:48 AM UTC-4, Chris Angelico wrote: Module names should be descriptive, not fancy. Interesting comment, on a mailing list for a language named after a snake, especially by a guy who claims to prefer an language named after a fish :-) As Tim already explained, it's named after Monty Python... ...Python FAQ 1.16. "Do I have to like "Monty Python's Flying Circus"?" "No, but it helps. Pythonistas like the occasional reference to SPAM (https://en.wikipedia.org/wiki/Spam_%28Monty_Python%29), and of course, nobody expects the Spanish Inquisition..." Sas -- https://mail.python.org/mailman/listinfo/python-list
Re: Sexism in the Ruby community: how does the Python community manage it?
Am 18.10.2013 15:09, schrieb Robert Kern: On 2013-10-18 05:03, Chris Angelico wrote: On Fri, Oct 18, 2013 at 2:14 PM, Steven D'Aprano wrote: On Thu, 17 Oct 2013 10:16:24 -0700, Roy Smith wrote: On Thursday, October 17, 2013 11:07:48 AM UTC-4, Chris Angelico wrote: Module names should be descriptive, not fancy. Interesting comment, on a mailing list for a language named after a snake, especially by a guy who claims to prefer an language named after a fish :-) It's not named after a snake, but after a British comedy group, "Monty Python". And I daresay that Pike is named after a long stick with a spike and axe on the end. Just 'cos that would be cooler than naming it after the fish. I don't know which it was named after (could also be a road, eg turnpike), but the language's logo is the fish. Our logo is a snake, so that's obviously not a good guide. :-) -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco I quote Guido: "Apart from being a computer scientist, I'm also a fan of "Monty Python's Flying Circus" (a BBC comedy series from the seventies, in the -- unlikely -- case you didn't know). It occurred to me one day that I needed a name that was short, unique, and slightly mysterious. And I happened to be reading some scripts from the series at the time... So then I decided to call my language Python. But Python is not a joke. And don't you associate it with dangerous reptiles either! (If you need an icon, use an image of the 16-ton weight from the TV series or of a can of SPAM :-)" -- https://mail.python.org/mailman/listinfo/python-list
Re: Will Python 3.x ever become the actual standard?
Am 24.10.2013 14:29, schrieb Damien Wyart: I am starting to have doubts as to whether Python 3.x will ever be actually adopted by the Python community at large as their standard. Years have passed, and a LARGE number of Python programmers has not even bothered learning version 3.x. Why am I bothered by this? Because of lot of good libraries are still only for version 2.x, and there is no sign of their being updated for v3.x. I get the impression as if 3.x, despite being better and more advanced than 2.x from the technical point of view, is a bit of a letdown in terms of adoption. Some Linux distributions will certainly switch to Python 3 by default, sooner or later. Fedora has decided to do so for their 22 release: http://lwn.net/Articles/571528/ -- DW Saucy Salamander (Ubuntu 13.10, released oct 17th) comes with Python 3.3. -- https://mail.python.org/mailman/listinfo/python-list
Re: To whoever hacked into my Database
Am 07.11.2013 21:29, schrieb Denis McMahon: On Thu, 07 Nov 2013 01:01:38 -0800, Ferrous Cranus wrote: Τη Πέμπτη, 7 Νοεμβρίου 2013 12:11:20 π.μ. UTC+2, ο χρήστης Mark Lawrence έγραψε: ... hope that this time she destroys ... So she is a SHE! How do you know that the person hacked into my DB is a female? How do you know he isn't? The fact that person n refers to the alleged hacker (which I suspect is just an artifact of your bodged and broken python and sql code) as having gender x does not mean that person n knows who the hacker is. If using a gender specific pronoun to refer to the hacker implies knowledge of the hacker's true identity, then as the first person to use a gender specific pronoun in this thread, in the original post, with the comment "He is done it twice, lets see if he will make it again!", you clearly know who the hacker is. If you were actually hacked, I'd guess it was most likely sql injection using a hand crafted get or post request that exploited some vulnerability that you have carelessly posted in an internet forum and then ignored advice to make secure. -- Denis McMahon, denismfmcma...@gmail.com Well, whoever she/he/it is, I am kind of fond of "them" - fancy a real Single Malt. I am paying... -- https://mail.python.org/mailman/listinfo/python-list
Re: To whoever hacked into my Database
Am 09.11.2013 15:07, schrieb Steven D'Aprano: ... Nikos, you have annoyed and alienated enough people here... Sorry, I DO NOT AGREE! These threads keep my entire office entertained. I would even go so far to suggest, that we should set up an entirely new mailing list for Nikos only, maybe something called like acropolis-list(at)python.org. Mea culpa, I am entirely aware that this is an IT list, but hey, when you have done 2x65ish hrs per week in a row - standing in for our Ops Guy, holidaying - you really start to appreciating little interruptions like this... Greekings ...oops, meant greetings from Tartan-Land, Sas&Co -- https://mail.python.org/mailman/listinfo/python-list