Sublime Forum

Python Defined Functions Not Printing

#1

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

#!/usr/bin/python import os, sys, subprocess, shlex, re, string print "Hello?"
then everything is good.

However, if I try:

#!/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:

#!/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:

#!/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:

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.

0 Likes

#2

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!

0 Likes

#3

Is it as straight-forward as ‘/foo/bar’ not being found? Do you need the first ‘/’?

0 Likes

#4

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.

0 Likes

#5

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).

0 Likes

#6

Perhaps then the current directory isn’t what you expect it to be

0 Likes