LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-05-2016, 08:32 PM   #1
Flexico
Member
 
Registered: Aug 2015
Distribution: Mint MATE
Posts: 121

Rep: Reputation: Disabled
Python Script Launch Options


I'm not sure if this is more a Python question or a Linux question, but here goes: I have a script file tied to the key combo Ctrl+Alt+P to navigate to my script folder and run Python. That part works.
Code:
#!/bin/bash
mate-terminal --working-directory="/home/flexico/Documents/Python_Scripts" --title="Python" --command python
However, I also want it to run a few lines of Python script, like import some standard libraries so I don't have to re-type them in every time. How do I do that? I tried adjusting the program like so:
Code:
#!/bin/bash
mate-terminal --working-directory="/home/flexico/Documents/Python_Scripts" --title="Python" --command "python /home/flexico/python_start.py"
But it just opens a blank Terminal window with a flashing cursor, which disappears when I click on it.
 
Old 12-05-2016, 08:51 PM   #2
Flexico
Member
 
Registered: Aug 2015
Distribution: Mint MATE
Posts: 121

Original Poster
Rep: Reputation: Disabled
In case it isn't clear, my goal is to have the Terminal stay open with Python running so I can input more commands. The "python_start.py" file just has commands to import a few modules.
 
Old 12-05-2016, 09:58 PM   #3
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Here you go: https://docs.python.org/2/tutorial/a...e-startup-file
 
Old 12-05-2016, 10:12 PM   #4
Flexico
Member
 
Registered: Aug 2015
Distribution: Mint MATE
Posts: 121

Original Poster
Rep: Reputation: Disabled
*google translate* ... A toothbrush ad in Japanese. Classy.

Last edited by Flexico; 12-05-2016 at 11:30 PM.
 
Old 12-05-2016, 11:04 PM   #5
Flexico
Member
 
Registered: Aug 2015
Distribution: Mint MATE
Posts: 121

Original Poster
Rep: Reputation: Disabled
Ok, after some fiddling I managed to get it to work ... sort of. When I open a Terminal prompt and type in "python", it works, but when I run my script ...
Code:
#!/bin/bash
mate-terminal --working-directory="/home/flexico/Documents/Python_Scripts" --title="Python" --command python
... It doesn't.

For the sake of anyone else reading this thread for answers, you have to add the following line to your ~/.bashrc file:
Code:
export PYTHONSTARTUP="filename"
(I'm saying this because it isn't expressly stated in the documentation.)
 
Old 12-05-2016, 11:25 PM   #6
Flexico
Member
 
Registered: Aug 2015
Distribution: Mint MATE
Posts: 121

Original Poster
Rep: Reputation: Disabled
Hmm, if I run my script file straight from the terminal, it works perfectly. However, when I use the keybind or double-click the script, it doesn't work. Maybe running it that way isn't triggering bash to look in bashrc.

I changed my code to
Code:
#!/bin/bash
cd /home/flexico/Documents/Python_Scripts
mate-terminal
Which does everything except actually run Python, so I just have to type in "python" and wham, it works. It seems like the command line has to actually be activated for it to load bashrc.
 
Old 12-05-2016, 11:33 PM   #7
Flexico
Member
 
Registered: Aug 2015
Distribution: Mint MATE
Posts: 121

Original Poster
Rep: Reputation: Disabled
GOT IT!
Code:
#!/bin/bash
source ~/.bashrc
cd /home/flexico/Documents/Python_Scripts
mate-terminal --title="Python" --command python
Google is my friend. =P
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Python Script to detect OS and update name server and options in resolve.conf on mult piyush128k Linux - Newbie 7 06-07-2015 07:59 PM
How to close open ports using a python script or a shell script in python ?? apanimesh061 Programming 3 11-20-2011 12:31 AM
LXer: A Simple Python Script to Launch digiKam LXer Syndicated Linux News 0 07-25-2011 08:20 PM
LXer: A Simple Python Script to Launch digiKam LXer Syndicated Linux News 0 07-25-2011 07:40 PM
How do I launch Python-IDLE? Gurduloo MEPIS 4 06-09-2005 12:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration