Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7686001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:22:50+00:00 2026-05-31T19:22:50+00:00

I usually write python in emacs. I’ll often want to re-evaluate my file, which

  • 0

I usually write python in emacs.

I’ll often want to re-evaluate my file, which I can do with Ctrl-C Ctrl-C, which causes the interpreter to reload the entire file and then I can carry on playing.

so if I’m writing a program that takes input, I’ll usually find myself with two lines:

lines = open("/home/jla/inputfile").readlines()
#lines = fileinput.input()

the first line is ‘what to do while developing’ (read from a known example input file)
the second is ‘what to do when run from the command line’ (read from stdin, or a provided file name)

Obviously this is bad, so I am thinking:

if in_emacs():
     lines = open("/home/jla/inputfile").readlines()
if run_from_shell():
     lines = fileinput.input()
else:
     oops()

And I know how to write oops(), but I am a bit stuck with in_emacs() and run_from_shell(), and I wonder if you wise ones can help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:22:52+00:00Added an answer on May 31, 2026 at 7:22 pm

    Shells opened by emacs should have the environment variable EMACS=t. At least this works on my emacs, YMMV.

    If that doesn’t fly for you, here’s how to find out what emacs-dependent environment variables python can see. Run from the shell and under emacs, and compare the outputs.

    import os
    for e in os.environ:
        if 'EMACS' in e:
            print e, os.environ[e]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I write a lot of .NET based plug-ins for other programs which are usually
We usually write stored procedures on the database which accepts xml and returns result
I usually perform things like this in C++, but I'm using python to write
I usually write C# programs for myself, or just parts of other applications. Now,
I usually write something like this: <mx:VBox height=100% width=155> <mx:Button label=b1 width=100%/> <mx:Buttonlabel=b2 width=100%/>
When I write an SQL statement, I usually write it like this SELECT COUNT(*)
When I retrieve any Scalar value from the database, I usually write code like
when releasing an instance that could exist or not, I usually write this: if
Usually i write my where statements as WHERE key=@0 then add a param. Now
I mostly write small scripts in python, about 50 - 250 lines of code.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.