Python Forum
How to define a global file?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to define a global file?
#1
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.
Reply
#2
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.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
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.
Reply
#4
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.
Reply
#5
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.
Reply
#6
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?
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#7
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.
Reply
#8
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.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#9
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.
Reply
#10
Actually that is crossed my mind after @scaperen's post. Post #5
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


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

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020