Re: [Tutor] 2.7.3 Popen argument issues
On Sat, Aug 25, 2012 at 11:02 PM, eryksun wrote: > > out_file = "testing.avi" > out_ip = "127.0.0.1" > out_port = "11300" > dst_file = '"transcode{vb=400}:std{access=file,mux=avi,dst=%s}"' % out_file > dst_http = '"std{access=http,mux=mpjpeg,dst=%s:%s}"' % (out_ip, out_port) > sout = "'#duplicate{dst=%s,dst=%s}'" % (dst_file, dst_http) > > cmd = "vlc http://%s:%s -I dummy --sout %s" % (ip, port, sout) > > p = subprocess.Popen(cmd.split()) Wow... That was silly of me. Don't use split(). It would split up arguments that have internal spaces. Just build the list. sout = "#duplicate{dst=%s,dst=%s}" % (dst_file, dst_http) cmd = ["vlc", "http://%s:%s"; % (ip, port), "-I", "dummy", "--sout", sout] p = subprocess.Popen(cmd) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] askopenfilename - columns missing in navigationwindow
On Sat, Aug 25, 2012 at 9:56 PM, Joel Levine wrote: > > from tkFileDialog import askopenfilename > fn=askopenfilename() > > I use this program repeatedly. Up to a few hours ago, the navigation window > opened with a full array of columns, including name and date. > > Once I mistakenly typed control-F (Find) instead of letters (for the > file). Now the navigation window opens with only one column, the name > column. Try running "tclsh" in the terminal. Then enter: package require Tk set fn [tk_getOpenFile] puts $fn exit Is it the same dialog as in Python? Knowing whether the problem is with Tcl/Tk or with Tkinter might get you closer to a solution. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 2.7.3 Popen argument issues
On Sat, Aug 25, 2012 at 11:02 PM, eryksun wrote: > > import subprocess > > ip = "192.168.0.2" > port = "1234" > > out_file = "testing.avi" > out_ip = "127.0.0.1" > out_port = "11300" > dst_file = '"transcode{vb=400}:std{access=file,mux=avi,dst=%s}"' % out_file > dst_http = '"std{access=http,mux=mpjpeg,dst=%s:%s}"' % (out_ip, out_port) > sout = "'#duplicate{dst=%s,dst=%s}'" % (dst_file, dst_http) > If that doesn't work, vlc might not like the extra quotes around sout. Try it without them: sout = "#duplicate{dst=%s,dst=%s}" % (dst_file, dst_http) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 2.7.3 Popen argument issues
On Sat, Aug 25, 2012 at 8:46 PM, Ray Jones wrote: > > Here is my Python call to vlc (error response to follow): > > vlcExec = sp.Popen(['vlc', 'http://' + ip + ':' + port, '-I dummy', > '--sout > \'#duplicate{dst="transcode{vb=400}:std{access=file,mux=avi,dst=outFile > + '.avi}",dst="std{access=http,mux=mpjpeg,dst=127.0.0.1:11300}"}\'']) > Arguments are split on spaces. For example, it's ['-I', 'dummy'], not ['-I dummy']. You can put the command in a string and split() it. Hopefully the following will work once you set the values you're using for ip/port. import subprocess ip = "192.168.0.2" port = "1234" out_file = "testing.avi" out_ip = "127.0.0.1" out_port = "11300" dst_file = '"transcode{vb=400}:std{access=file,mux=avi,dst=%s}"' % out_file dst_http = '"std{access=http,mux=mpjpeg,dst=%s:%s}"' % (out_ip, out_port) sout = "'#duplicate{dst=%s,dst=%s}'" % (dst_file, dst_http) cmd = "vlc http://%s:%s -I dummy --sout %s" % (ip, port, sout) p = subprocess.Popen(cmd.split()) To answer your initial question, you could call a Python script (or a Bash script if you prefer) instead of vlc. In Python, just print out the list sys.argv. cmd = "python argtest.py http://%s:%s -I dummy --sout %s" % (ip, port, sout) p = subprocess.Popen(cmd.split()) # argtest.py import sys print "\nArgs:" for arg in sys.argv: print arg ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] askopenfilename - columns missing in navigationwindow
Mystery of the day: I'm using Python 2.6. My program uses from tkFileDialog import askopenfilename and fn=askopenfilename() I use this program repeatedly. Up to a few hours ago, the navigation window opened with a full array of columns, including name and date. Once I mistakenly typed control-F (Find) instead of letters (for the file). Now the navigation window opens with only one column, the name column. The problem is there in my program, or in the IDLE interpreter, or in a terminal Python interpreter -- just using the two lines, the import statement and the askopenfilename. This is Python 2.6 on a Mac. A complete restart of the machine did not solve the problem. Any suggestions? Joel Levine ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] 2.7.3 Popen argument issues
Is there a method by which I can get an exact representation of command line arguments passed by Popen as seen by the called program? The argument error I receive shows me an argument that looks exactly like the argument that I use with Bash (it should - I copied and pasted it) - but the Bash version works while the Python version doesn't. The purpose is to capture http streaming video to a file and also split it out to a local port so that I can pop in and monitor where I am in the stream. Here is my Bash call to vlc (it works): vlc http://"$HOST":$PORT -I dummy --sout '#duplicate{dst="transcode{vb=400}:std{access=file,mux=avi,dst=testing.avi}",dst="std{access=http,mux=mpjpeg,dst=127.0.0.1:11300}"}' & Here is my Python call to vlc (error response to follow): vlcExec = sp.Popen(['vlc', 'http://' + ip + ':' + port, '-I dummy', '--sout \'#duplicate{dst="transcode{vb=400}:std{access=file,mux=avi,dst=outFile + '.avi}",dst="std{access=http,mux=mpjpeg,dst=127.0.0.1:11300}"}\'']) (That is not an escaped double quote at the end - that is " \' " and " ' "). Here is the resulting error from vlc: vlc: unknown option or missing mandatory argument `--sout '#duplicate{dst="transcode{vb=400}:std{access=file,mux=avi,dst=testing.avi}",dst="std{access=http,mux=mpjpeg,dst=127.0.0.1:11300}"}'' ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] reason(s) for trailing comma in dict declarations
On Sat, Aug 25, 2012 at 1:39 PM, Alan Gauld wrote: > > two adjacent strings without a comma get combined into a single string. > Its a feature... mainly a remnant from the C foundations I suspect. As a feature it can come in handy with long strings in expressions. Just for reference about the "C foundations", here's a similar example in C. #include int main() { int i, x_len; char *x[] = { "string1", "string2", "string3" /* no comma */ "string4" }; x_len = sizeof(x) / sizeof(x[0]); for (i = 0; i < x_len; i++) { printf("%s\n", x[i]); } return 0; } Output: string1 string2 string3string4 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] reason(s) for trailing comma in dict declarations
On 25/08/12 16:53, aklei...@sonic.net wrote: in sequences of strings to prevent them from being "silently"<=>"concatenated" if you were to add an entry and forget the comma. error if the comma is omitted when adding an entry but I don't understand the (potential) concatenation problem. Consider: >>> 'fred','joe' ('fred', 'joe') >>> 'fred''joe' 'fredjoe' >>> two adjacent strings without a comma get combined into a single string. Its a feature... mainly a remnant from the C foundations I suspect. HTH, -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] reason(s) for trailing comma in dict declarations
Thanks for the clarification. Now it is clear. ak > On Sat, Aug 25, 2012 at 11:53 AM, wrote: >> >> Put each entry on its own line, indented by two spaces, and leave a >> trailing comma on the last entry. The latter is especially important >> in sequences of strings to prevent them from being >> "silently"<=>"concatenated" if you were to add an entry and forget the >> comma. >> """ >> >> When I first saw this I thought it would lead to a syntax error so tried >> it out.. >> Then played with it to try to recreate the '"silently"<=>"concatenated"' >> problem but couldn't. I like this syntax because it avoids the syntax >> error if the comma is omitted when adding an entry but I don't >> understand >> the (potential) concatenation problem. >> >> Could you explain please? > > Sure, I said the problem is with "sequences", not mappings. The syntax > for a dictionary will catch the mistake. But try it with a list. > > x = [ > "string1", > "string2", > "string3" # no comma > ] > > Later you decide to add "string4" but forget to add the comma: > > x = [ > "string1", > "string2", > "string3" # no comma > "string4" > ] > > Result: > > ['string1', 'string2', 'string3string4'] > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] reason(s) for trailing comma in dict declarations
On Sat, Aug 25, 2012 at 11:53 AM, wrote: > > Put each entry on its own line, indented by two spaces, and leave a > trailing comma on the last entry. The latter is especially important > in sequences of strings to prevent them from being > "silently"<=>"concatenated" if you were to add an entry and forget the > comma. > """ > > When I first saw this I thought it would lead to a syntax error so tried > it out.. > Then played with it to try to recreate the '"silently"<=>"concatenated"' > problem but couldn't. I like this syntax because it avoids the syntax > error if the comma is omitted when adding an entry but I don't understand > the (potential) concatenation problem. > > Could you explain please? Sure, I said the problem is with "sequences", not mappings. The syntax for a dictionary will catch the mistake. But try it with a list. x = [ "string1", "string2", "string3" # no comma ] Later you decide to add "string4" but forget to add the comma: x = [ "string1", "string2", "string3" # no comma "string4" ] Result: ['string1', 'string2', 'string3string4'] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] reason(s) for trailing comma in dict declarations
aklei...@sonic.net wrote: > Part of a previous post: > """ > Here's the style I'd use: > > combos = { > 0: 'id', > 2: 'country', > 3: 'type', > 5: 'lat', > 6: 'lon', > 12: 'name', > } > > Put each entry on its own line, indented by two spaces, and leave a > trailing comma on the last entry. The latter is especially important > in sequences of strings to prevent them from being > "silently"<=>"concatenated" if you were to add an entry and forget the > comma. > """ > > When I first saw this I thought it would lead to a syntax error so tried > it out.. > Then played with it to try to recreate the '"silently"<=>"concatenated"' > problem but couldn't. I like this syntax because it avoids the syntax > error if the comma is omitted when adding an entry but I don't understand > the (potential) concatenation problem. > > Could you explain please? Consider the following list: >>> ["the" ... "quick", ... "brown" ... "fox"] ['thequick', 'brownfox'] "the" and "quick" look like two entries in the list, but as the comma is missing they are merged together. Same for "brown" and "fox". I think you cannot run into this problem with dictionaries as accidentally merging a value and a key would result in a syntax error at the second colon: >>> {"the": "quick" ... "brown": "fox"} File "", line 2 "brown": "fox"} ^ SyntaxError: invalid syntax ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] reason(s) for trailing comma in dict declarations
Part of a previous post: """ Here's the style I'd use: combos = { 0: 'id', 2: 'country', 3: 'type', 5: 'lat', 6: 'lon', 12: 'name', } Put each entry on its own line, indented by two spaces, and leave a trailing comma on the last entry. The latter is especially important in sequences of strings to prevent them from being "silently"<=>"concatenated" if you were to add an entry and forget the comma. """ When I first saw this I thought it would lead to a syntax error so tried it out.. Then played with it to try to recreate the '"silently"<=>"concatenated"' problem but couldn't. I like this syntax because it avoids the syntax error if the comma is omitted when adding an entry but I don't understand the (potential) concatenation problem. Could you explain please? alex ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Error message...
Thank you everyone for your help with my question - I understand what I was doing wrong now. I know I'm posting wrongly so I'm going to go and figure out how to do it properly for the future. Have a great day. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Error message...
>Hi Victoria. im a total beginner aswell but i noticed something. shouldnt this >line: else: return s(0) == s(-1) and isPalindrome (s[1:-1]) be else: return s[0] == s[-1] and isPalindrome (s[1:-1]) it looks like you have the string s as a function which you are trying to call. what you wanted was an index position right? which should be s[] instead of s(). thanks for the help David. Sorry about the sent mail. Gmail is pretty confusing for me:( ___ > 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