0

I am trying to rewrite a Perl script a coworker made that you lets you bookmark directories.

The way it works is you type go add dir while in a folder and from anywhere else in terminal you type go dir and you will go to the bookmarked directory.

From what I can tell go is a bash function that calls the perl script with the following code: cd (godir). It seems that to print out anything other than a dir it prints STDERR. When I use sys.stderr.write() in python it prints out the text but it also prints out cd: The directory 'None' does not exist

This is an edit because my original question wasn't specific enough. I actually found a solution: My fish function will eval whatever the Python script returns

eval (python go.py $argv) 
2
  • I apologize, I was in a hurry and did not provide specific enough information... I'm going to edit the question with much better information Commented Nov 8, 2015 at 4:03
  • I suspect, based on the added information, that your original problem was the different behavior of print in Perl and Python when given a "nonexistent" value: in Perl, print undef will print nothing, whereas in Python, print None will, in fact, print the string None. Glad to see you found a work-around, though. Commented Nov 8, 2015 at 14:56

2 Answers 2

4

In Python 2 you can do:

print >> sys.stderr, """Text to print""" 

For Python 3 the syntax is:

print("""Text to print""", file=sys.stderr) 

Of course import sys is required in both cases to import the sys module.

Sign up to request clarification or add additional context in comments.

1 Comment

... possibly with triple quotes for multiline text.
0

This was answered here

I found this to be the only one short + flexible + portable + readable:

from __future__ import print_function ...

def warning(*objs): print("WARNING: ", *objs, file=sys.stderr)

1 Comment

Hi dvdt, welcome to Stack Overflow. If you ever find a question that can be answered by copy-pasting another Stack Overflow answer verbatim, please flag the question as a duplicate by clicking the "flag" button beneath the question. Marking questions as duplicates makes it easier for users to find them when searching.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.