Oct-05-2016, 05:10 AM
I need to set up a file as a log file in my python program. So basically I need to create a global file. I am just wondering what is the best way to define a global file in python? Thanks.
How to define a global file?
|
Oct-05-2016, 05:10 AM
I need to set up a file as a log file in my python program. So basically I need to create a global file. I am just wondering what is the best way to define a global file in python? Thanks.
Oct-05-2016, 05:14 AM
I don't get you what you mean with the fraze 'a global file'. With Python you can read and write any file as long as you have permissions to do that.
Oct-05-2016, 05:16 AM
Logging is a fairly complex subject. Where you declare the file, and open it is very much dependent on how your code is structured.
the easiest thing to do is go to https://pypi.python.org/ and query 'logging' find a suitable module, install it and just import into your code.
Oct-05-2016, 05:32 AM
Actually, all I want is to trace the program execution and list the functions executed during the program run. Should I simply use trace module? Thanks.
in some cases i cheat to do logging. i open() or os.open() a file and os.dup2() its file descriptor to stdout (1). i am running Linux. i have no idea if this works in Windows (nor do i care). then all print() goes to that file, even in called functions and forked processes (which i do a lot of).
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
I am running linux too. @scaperen, you say that all output from a program can be wrote in a file? Which os. method is doing that?
I once wanted to output data from top to a file, so I used this
top -n 10 -b > top-output.txt to run the process.
Oct-05-2016, 12:42 PM
Output redirection is one thing I know well but I was asking how to do it from Python script. I will look at os module later to see what is provided.
Oct-05-2016, 12:51 PM
Oh sorry then wavic, I didn't catch that bit. I will be glad to hear what you found out if you will look into it.
Actually that is crossed my mind after @scaperen's post. Post #5
|
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
Global variable does not seem to be global. | Columbo | 6 | 3,708 |
Jul-15-2019, 11:00 PM Last Post: Columbo |
|
define methods in another file | bb8 | 13 | 6,813 |
Mar-04-2018, 06:37 AM Last Post: Python_n00b_06 |
|
[Python Class] save method output to global file/list | Vijay | 3 | 5,070 |
Dec-23-2017, 03:20 AM Last Post: Vijay |