473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

printing all variables

Good day,

I would like to know if there is a way to print all the variables set
in a python program with having to write
"print variable" on all?

sincerely,
Sheldon

Jun 12 '06 #1
2 1992
Sheldon wrote:
Good day,

I would like to know if there is a way to print all the variables set
in a python program with having to write
"print variable" on all?

Not all the variables in a program (that would be rather more than you
want), but you can print all the variables in a specific namespace easily
enough:
from pprint import pprint
def f(x): pprint(locals())

f(2) {'x': 2} pprint(globals()) {'__builtins__': <module '__builtin__' (built-in)>,
'__doc__': None,
'__name__': '__main__',
'f': <function f at 0x00B45B30>,
'pprint': <function pprint at 0x00B45BB0>} class C: classvar = []
def __init__(self, n):
self.n = n

c = C(3)
pprint(vars(c)) {'n': 3} pprint(vars(C)) {'__doc__': None,
'__init__': <function __init__ at 0x00B4A070>,
'__module__': '__main__',
'classvar': []}

Jun 12 '06 #2

Duncan Booth skrev:
Sheldon wrote:
Good day,

I would like to know if there is a way to print all the variables set
in a python program with having to write
"print variable" on all?

Not all the variables in a program (that would be rather more than you
want), but you can print all the variables in a specific namespace easily
enough:
from pprint import pprint
def f(x): pprint(locals())

f(2) {'x': 2} pprint(globals()) {'__builtins__': <module '__builtin__' (built-in)>,
'__doc__': None,
'__name__': '__main__',
'f': <function f at 0x00B45B30>,
'pprint': <function pprint at 0x00B45BB0>} class C: classvar = []
def __init__(self, n):
self.n = n

c = C(3)
pprint(vars(c)) {'n': 3} pprint(vars(C)) {'__doc__': None,
'__init__': <function __init__ at 0x00B4A070>,
'__module__': '__main__',
'classvar': []}


Thanks Duncan! This really helps!

/Sheldon

Jun 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mr. B | last post by:
This is driving me NUTZ!!! I've been screwing around on this for a week now. And I have tried to find examples similar to what I have (nada). Got lots of streaming a TXT file... bah! I am...
2
by: Jack Russell | last post by:
Gee vb.net makes me feel dumb! My understanding is that I set up and do all of my printing in the printdocument printpage and handler using various graphics methods such as drawstring. Is...
2
by: gerb | last post by:
Hello, I realise this is not a pure Javascript question, and that VBscript is probably involved at some point, though not as much as I fear. If you opened this item looking for a pute Javascript...
10
by: Jeff B. | last post by:
Has anyone come across a decent algorithm for implementing word wrap features in .net printing? I have a small component that uses basic printing techniques (i.e. e.Graphics.DrawString in a...
6
by: Bill | last post by:
Hi I am trying to get my listbox items to print if they stream past the one page mark. my code is working for one page of information (if the e.hasmorepages) is not there. But I am having...
0
by: Jason Hunt | last post by:
Hello All, So far I've been using the "regular" way of printing with PrintDocument, by maintaining the X and Y positions, drawing rectangles, lines, strings of text, etc. I'd like to have a...
2
by: Hexman | last post by:
Hello All, I'm now getting into the reporting phase of my application development. I need to print not only continuous page reports from a datasource (database, datagridview, listboxes, etc),...
2
by: =?Utf-8?B?TUFUVA==?= | last post by:
What i am trying to accomplish is programatically creating Invoices and then Printing them out. I don't really need to "View" them before they print. How I am trying to do this is I have created...
2
by: deepakfordotnet | last post by:
Hi, First of all let me confess that I could not get the solution to the same problem from an earlier post Printing :by Mr.Richard MSL (dated September 24th 2006) working. (Replied by Mr.Walter...
0
it0ny
by: it0ny | last post by:
Hi guys, thanks I am fairly new to this forum so I hope I chose the right place to post this question. I try to make my program printout a deposit's report. I created a class to store the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.