Home Download Buy Blog Forum Support

Python Defined Functions Not Printing

Python Defined Functions Not Printing

Postby Robin Hood on Sun Apr 01, 2012 5:39 pm

Operating System: Mac OS X Lion 10.7.3
Sublime Text 2 Version: 2181

I'm sorry, I've only just started programming and am switching over (or hoping to) from Textmate.

Sublime feels SO much better, but I haven't managed to get anything like the "Run" option in Textmate (where I can just look at the output and stuff from the text editor itself. I can't figure out what to modify in "Python.sublime-build" (if that's even what I'm supposed to be editing).

If I use
Code: Select all
#!/usr/bin/python
import os, sys, subprocess, shlex, re, string
print "Hello?"

then everything is good.

However, if I try:
Code: Select all
#!/usr/bin/python
import os, sys, subprocess, shlex, re, string
def probe_file(filename):
    print "Hello?"
[probe_file(f) for f in os.listdir('/foo/bar') if os.path.isfile(f) and not f.startswith('.')]
print "Hello World!"

nothing comes back; I just see "[Finished]"

Ditto with:
Code: Select all
#!/usr/bin/python
import os, sys, subprocess, shlex, re, string
def probe_file(filename):
    output = subprocess.Popen(['ffprobe', '-show_format', '-pretty', '-loglevel', 'verbose', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
    print output
[probe_file(f) for f in os.listdir('.') if os.path.isfile(f) and not f.startswith('.')]

(Both print fine if I run them in terminal).

What's (perhaps) curious to me is if I try to bypass this, I get weird errors from python that I don't understand:
Code: Select all
#!/usr/bin/python
import os, sys, subprocess, shlex, re, string
from subprocess import call
for f in os.listdir('foo/bar'): print f
for f in os.listdir('foo/bar'): output = subprocess.Popen(['ffprobe', '-show_format', '-pretty', '-loglevel', 'verbose', f], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
output = output[0] + output[1]
print output

returns:
Code: Select all
My File Name.avi
Traceback (most recent call last):
  File "/Users/../test", line 5, in <module>
    for f in os.listdir('/foo/bar'): output = subprocess.Popen(['ffprobe', '-show_format', '-pretty', '-loglevel', 'verbose', f], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1202, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
[Finished]


All this code runs smoothly in Terminal.
Robin Hood
 
Posts: 4
Joined: Sun Apr 01, 2012 5:03 pm

Re: Python Defined Functions Not Printing

Postby Robin Hood on Tue Apr 03, 2012 3:59 pm

Seems to having something to do with whether or not it has to call on particular...modules/functions in python?

I'm seriously sorry if this is something I'm just annoyingly ignorant about. But every time it asks me if I want to purchase a license it makes me wish I could support the development of this VERY useful little tool. (I'm a big believer in supporting good developers, good products, etc. even in FOSS or non-expiring "Beer Free" software like Sublime seems to be at the moment.)

Hope to hear back!
Robin Hood
 
Posts: 4
Joined: Sun Apr 01, 2012 5:03 pm

Re: Python Defined Functions Not Printing

Postby agibsonsw on Tue Apr 03, 2012 4:25 pm

Is it as straight-forward as '/foo/bar' not being found? Do you need the first '/'?
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Python Defined Functions Not Printing

Postby Robin Hood on Wed Apr 04, 2012 8:12 am

No, the function has been changed from os.listdir('.') to glob.glob('*') and has been checked and working fine in Terminal and Textmate in a lot of cases.
Robin Hood
 
Posts: 4
Joined: Sun Apr 01, 2012 5:03 pm

Re: Python Defined Functions Not Printing

Postby Robin Hood on Mon Apr 16, 2012 7:24 am

I'm a paying customer now. I suppose I might be submitting a ticket soon.

Was hoping it was an easy fix (for Textmate I think there was just a page telling you what to cut-and-paste to get it all working fine).
Robin Hood
 
Posts: 4
Joined: Sun Apr 01, 2012 5:03 pm

Re: Python Defined Functions Not Printing

Postby jps on Mon Apr 16, 2012 7:58 am

Robin Hood wrote:No, the function has been changed from os.listdir('.') to glob.glob('*') and has been checked and working fine in Terminal and Textmate in a lot of cases.

Perhaps then the current directory isn't what you expect it to be
jps
Site Admin
 
Posts: 3058
Joined: Wed Mar 19, 2008 12:33 pm


Return to Technical Support

Who is online

Users browsing this forum: Yahoo [Bot] and 16 guests