473,563 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting a class name from within main

Hi,

Lets say I have the following class -

class MyClass:
def __init__(self):
print (__name__.split ("."))[-1]

if __name__ == '__main__':
MyClassName = "MyClass"

I can print the name of the class from within the class scope as seen
above in the init, but is there any way of printing it from within the
main without creating an object of the MyClass type. I need to assign
the name of the class within my script, to a variable in main.

Thanks,

Barry.

Feb 7 '07 #1
3 1295
bg***@yahoo.com wrote:
Hi,

Lets say I have the following class -

class MyClass:
def __init__(self):
print (__name__.split ("."))[-1]

if __name__ == '__main__':
MyClassName = "MyClass"

I can print the name of the class from within the class scope as seen
above in the init, but is there any way of printing it from within the
main without creating an object of the MyClass type. I need to assign
the name of the class within my script, to a variable in main.

Thanks,

Barry.
>>class A:
.... pass
....
>>print A.__name__
A
>>>
--
Robin Becker

Feb 7 '07 #2
In <11************ *********@s48g2 000cws.googlegr oups.com>, bg_ie wrote:
class MyClass:
def __init__(self):
print (__name__.split ("."))[-1]

if __name__ == '__main__':
MyClassName = "MyClass"

I can print the name of the class from within the class scope as seen
above in the init, but is there any way of printing it from within the
main without creating an object of the MyClass type. I need to assign
the name of the class within my script, to a variable in main.
Yes::

print MyClass.__name_ _

Ciao,
Marc 'BlackJack' Rintsch
Feb 7 '07 #3
On Wed, Feb 07, 2007 at 01:02:39AM -0800, bg***@yahoo.com wrote:
Hi,

Lets say I have the following class -

class MyClass:
def __init__(self):
print (__name__.split ("."))[-1]
I would spell this:
print self.__class__. __name__
>
if __name__ == '__main__':
MyClassName = "MyClass"

I can print the name of the class from within the class scope as seen
above in the init, but is there any way of printing it from within the
main without creating an object of the MyClass type. I need to assign
the name of the class within my script, to a variable in main.

Thanks,

Barry.

--
http://mail.python.org/mailman/listinfo/python-list
Feb 8 '07 #4

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

Similar topics

8
1403
by: abbylee26 | last post by:
User enters account number if another account number is needed User clicks add account which creates another row When validating when they hit submit I want to check to make sure they tell us how much money to charge to all account numbers except the first one (all remaining money goes on the first account number) within the header...
5
2214
by: Jacek Dziedzic | last post by:
Hi! In my main() function I have a last-resort exception construct that looks like this: int main() { try { // ... program code }
7
2367
by: Thomas Matthews | last post by:
Hi, I am converting my table and record classes into templates. My issue is the syntax of declaring a friend class within the template. I have searched the C++ FAQ Lite (web), the C++ newsgroups, "Thinking In C++" to no avail. Background ----------
12
2004
by: Sunny | last post by:
Hi All, I have a serious issue regarding classes scope and visibility. In my application, i have a class name "TextFile", and also a few other classes like "TotalWords", "TotalLines" and etc.., which are suppose to describe the structure of my main TextFile class. Also i have created some custom collection classes, which only take items of...
5
1680
by: Xarky | last post by:
Hi, I have the following in the project, with the following desgin. // class 1, which is a windows form namespace Name { public class aaaa {
0
3202
by: Daniel Sélen Secches | last post by:
I found a good class to do a simple FTP. Very good.... I'm posting it with the message, i hope it helps someone ============================================================== Imports System.Net
7
1535
by: RSH | last post by:
This is probably a very simple question but... How do I get the instantiated name of an object from within the class? Example: Sub main Dim c1 as new TestClass() c1.PrintName()
3
1264
by: johnny | last post by:
Can a class inside a module, access a method, outside of class, but inside of the module? Eg. Can instance of class a access main, if so how? What is the scope of "def main()" interms of class A? myModule: class A: main()
2
6644
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double) Location: class Week5MortgageGUI Week5MortgageLogic allint = logic.allInterest(amount, term, rate); Week5MortgageGUI.java:152:cannot find symbol...
0
7583
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7638
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7948
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.