Too many imports to use a business class library?
Hi all, I am new to python. Sorry if this is too novice question, but I could not find an answer yet. While coding a business class library, I think it is preferable to have one class per source file, rather than combining all classes into one file, considering multiple developers developing the classes. So, as per my study of python, a developer using the business class library has to write so many imports, one per class. Like: from person import Person from contact import Contact . . . Is there not a simple solution, a single import and you are able to use all the classes? Is there anything wrong in my approcah? Waiting for suggestions. Thanks in advance. Sanjay -- http://mail.python.org/mailman/listinfo/python-list
Re: Too many imports to use a business class library?
Thanks a lot to all for the to-the-point info, quite vital to me... Sanjay -- http://mail.python.org/mailman/listinfo/python-list
How to have application-wide global objects
Probably a newcomer question, but I could not find a solution. I am trying to have some singleton global objects like "database connection" or "session" shared application wide. Trying hard, I am not even being able to figure out how to create an object in one module and refer the same in another one. "import" created a new object, as I tried. Badly need guidences. Thanks a lot Sanjay -- http://mail.python.org/mailman/listinfo/python-list
Re: How to have application-wide global objects
Hi Bruno, Thanks a lot for the reply. In order to post here, I wrote a very simple program now, and it seems working! I can diagnose the original problem now. There might be some other problem. Pardon me if I am too novice but I could not make out the meaning of this phrase from your reply: "(at the module's to level)" Thanks Sanjay -- Bruno Desthuilliers wrote: > Sanjay wrote: > > Probably a newcomer question, but I could not find a solution. > > > > I am trying to have some singleton global objects like "database > > connection" or "session" shared application wide. > > Whenever possible, dont. If you really have no other way out, create the > 'singleton' in it's module (at the module's to level), then import the > module. > > > Trying hard, I am not even being able to figure out how to create an > > object in one module and refer the same in another one. "import" > > created a new object, as I tried. > > I'd like to know what you actually tried. > > > -- > bruno desthuilliers > python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for > p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Re: How to have application-wide global objects
Got crystal clear. Thanks a lot to all for the elaborated replies. Sanjay -- http://mail.python.org/mailman/listinfo/python-list
Partial classes
Hi All, Not being able to figure out how are partial classes coded in Python. Example: Suppose I have a code generator which generates part of a business class, where as the custome part is to be written by me. In ruby (or C#), I divide the code into two source files. Like this: GeneratedPerson.rb Class Person . . . End Class HandcraftedPerson.rb Class Person . . . End Class The intrepretor adds the code in both to compose the class Person. What is the equivalent in Python? Inheriting is a way, but is not working in all scenerios. Thanks Sanjay -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial classes
Hi Alex, Thanks for the input. Being new to Python, and after having selected Python in comparison to ruby (Turbogears vs Rails) , is jerks me a bit. In my openion it should be an obvious and easy to implement feature and must be, if not already have been, planned in future releases of Python. Would love to listen to others. Sanjay -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial classes
> Can you flesh out your use case a little bit and tell why you can't solve > the problem with inheritance or a meta class? I have to study about metaclass and see whether this can be handled. It seemed inheritence is not working. PROBLEM: Separating plumbing code and business logic while using SQLAlchemy ORM. Database script: CREATE TABLE person ( id SERIAL, passport VARCHAR(50) NOT NULL, blocked BOOLEAN NOT NULL DEFAULT FALSE, first_name VARCHAR(30) NOT NULL, middle_name VARCHAR(30) NULL, last_name VARCHAR(30) NOT NULL, email VARCHAR(100) NOT NULL, used_bytes INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(id) ); CREATE TABLE contact ( person_id INTEGER NOT NULL REFERENCES person, contact_id INTEGER NOT NULL REFERENCES person, favorite BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY(person_id, contact_id) ); DB definitions and plumbing code goes into one module, say db.py: import sqlalchemy.mods.threadlocal from sqlalchemy import * global_connect('postgres://userid:[EMAIL PROTECTED]:5432/tm') person_tbl = Table('person', default_metadata, autoload = True) class Person(object): pass contact_tbl = Table('contact', default_metadata, autoload = True) class Contact(object): pass assign_mapper(Person, person_tbl, properties = { 'contacts' : relation(Contact, primaryjoin=person_tbl.c.id==contact_tbl.c.person_id, association=Person) }) assign_mapper(Contact, contact_tbl, properties = { 'person' : relation(Person, primaryjoin=person_tbl.c.id==contact_tbl.c.contact_id) }) Business logic in another module, say bo.py Class PersonBO(Person): def Block(): blocked = True While using PersonBO in another module, like this: p1 = PersonBO(passport = "[EMAIL PROTECTED]", first_name='john', last_name='smith', email = "[EMAIL PROTECTED]") p2 = PersonBO(passport = "[EMAIL PROTECTED]", first_name='ed', last_name='helms', email = "[EMAIL PROTECTED]") p3 = PersonBO(passport = "[EMAIL PROTECTED]", first_name='jonathan', last_name='lacour', email = "[EMAIL PROTECTED]") # add a contact p1.contacts.append(Contact(person=p2)) the following error message occurs: AttributeError: 'PersonBO' object has no attribute 'contacts' What I guess, from my limited knowledge of the technologies involved, is that assign_mapper does some magic only on Person class, and things work. But after inheritence, it is not working. The point in general, to my knowledge, about inheritance is that it can't be a substitute for all the usages of partical classes. Metaclass is a new concept for me, which I have to study. As far as my project is concerned, I have found out some other way of doing the things, and it is no more an issue. Thanks a lot, Sanjay -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial classes
Thanks for the code showing how to implement partial classes. Infact, I was searching for this code pattern. I will have a study on metaclass and then try it. Thanks Sanjay -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial classes
> > Class PersonBO(Person): > > def Block(): > > blocked = True > > > shouldn't it be: > class PersonBO(Person): > def block(self): > self.blocked = True > Yes, it should be as you mentioned. However, I had posted it to elaborate the case. Actually, I tested using the following code: class PersonBO(Person): pass > > As far as my project is concerned, I have found out some other way of > > doing the things, > > Care to explain your solution ? For the time being, I am not separating the plumbing and business logic. When I need to, I shall come back to this post, study all the ideas suggested, and jot down the pattern suitable to me. The code pattern using metaclass looked interesting to me. Thanks Sanjay -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial classes
> Anyway, I would suggest you NOT to use this code in production. Yes, > Python > can imitate Ruby, but using this kind of classes would confuse > everybody and > make your code extremely unpythonic. As always, consider changing your > mindset, > when you switch language. For you problem, you could just put your > client > methods in a file, and add them to your original class with setattr, if > you don't > want to use inheritance. It would be still better that magically > transform your > classes with a metaclass. Thanks for the much needed guidence. Sanjay -- http://mail.python.org/mailman/listinfo/python-list
Setting application-wide global datetime format
Hi All, Being an amateur in python, I am unable to find a way (if there is any) to set a datetime display format once globally in a web application (using turbogears), so that everytime I don't have to use routines like strftime. Seeking help. thanks sanjay -- http://mail.python.org/mailman/listinfo/python-list
Routine for prefixing '>' before every line of a string
Hi All, Is somewhere a routine useful to convert a string to lines of maxsize, each prefixed with a '>'. This is a typical requirement for 'keeping existing text while replying to a post in a forum'. It can be developed, but if something obvious is already there(I being new to python might not be aware), than it would be great just to reuse it! thanks sanjay -- http://mail.python.org/mailman/listinfo/python-list
Re: Routine for prefixing '>' before every line of a string
Thanks a lot, guys! sanjay -- http://mail.python.org/mailman/listinfo/python-list
pytz giving incorrect offset and timezone
Hi All, Using pytz, I am facing a problem with Asia/Calcutta, described below. Asia/Calcutta is actually IST, which is GMT + 5:30. But while using pytz, it was recognized as HMT (GMT + 5:53). While I digged into the oslan database, I see the following: # Zone NAME GMTOFF RULES FORMAT [UNTIL] Zone Asia/Calcutta 5:53:28 - LMT 1880 # Kolkata 5:53:20 - HMT 1941 Oct # Howrah Mean Time? 6:30 - BURT 1942 May 15 # Burma Time 5:30 - IST 1942 Sep 5:30 1:00 IST 1945 Oct 15 5:30 - IST Searching in this group, I saw a similar problem posted at http://groups.google.co.in/group/comp.lang.python/browse_thread/thread/55496e85797ac890 without any solutions. I mailed to Stuart and also posted it at the launchpad of pytz, but did not get any response. Unable to know how to proceed further. Any suggestion will be of vital help. thanks Sanjay -- http://mail.python.org/mailman/listinfo/python-list
pytz giving incorrect offset and timezone
Hi All, I am facing some strange problem in pytz. The timezone "Asia/Calcutta" is actually IST, which is GMT + 5:30. But while using pytz, it is being recognized as HMT (GMT + 5:53). While I digged into the oslan database, I see the following: # Zone NAME GMTOFF RULES FORMAT [UNTIL] Zone Asia/Calcutta 5:53:28 - LMT 1880 # Kolkata 5:53:20 - HMT 1941 Oct # Howrah Mean Time? 6:30 - BURT 1942 May 15 # Burma Time 5:30 - IST 1942 Sep 5:30 1:00 IST 1945 Oct 15 5:30 - IST A similar problem is also posted at http://groups.google.co.in/group/comp.lang.python/browse_thread/thread/55496e85797ac890 without any responnses. Unable to know how to proceed. Needing help. Tried posting in launchpad and mailed to Stuart, but yet to get any response. thanks Sanjay -- http://mail.python.org/mailman/listinfo/python-list
Posted messages not appearing in this group
Hi All, I tried posting in this group twice since last week, but the messages did not appear in the forum. Don't know why. Trying this message again... Sanjay -- http://mail.python.org/mailman/listinfo/python-list
Re: pytz giving incorrect offset and timezone
Hi Simon, localize worked perfectly. Thanks a lot for the vital help! Your elaboration on the concepts was also very nice and informative! thanks Sanjay -- http://mail.python.org/mailman/listinfo/python-list
pytz has so many timezones!
Hi All, I am using pytz.common_timezones to populate the timezone combo box of some user registration form. But as it has so many timezones (around 400), it is a bit confusing to the users. Is there a smaller and more practical set? If not, some suggestions on how to handle the registration form effectively would help me a lot. thanks Sanjay -- http://mail.python.org/mailman/listinfo/python-list
Re: pytz has so many timezones!
> Windows timezone selector only lists about 80 timezones. But why force > the user to select timezone? Let them select from a list of countries > and then infer the timezone from that data. With multiple alternatives > for countries with more than one timezone, United States EST, United > States PST and so on. > I think the problem is displaying a dropdown list of timezones. People > have little idea of how their timezones are called; it would be better > to list countries, which are many but nicely alphabetized, and map the > country to its only timezone, or for the few large countries with more > than a TZ offer a choice later. Thanks for the suggestions! 1. I am unable to understand how Windows manages with only 80 whereas pytz has 400. Understanding this can be a nice clue for my work. Any insights? 2. Mapping the timezones to countries is a nice idea. Any idea how to go about it - I mean whether I have to collect the data manually and do it, or some better way is available - will help me a lot. thanks Sanjay -- http://mail.python.org/mailman/listinfo/python-list
Re: pytz has so many timezones!
> It's not clear at all from the OPs post exactly what functionality he > is trying to derive from the timezone. Since timezones (obviously) > contain more information than just the GMT offset (otherwise we > wouldn't even have them), he may very well want to use the timezone > given by the user to display correct local time to them. In this case, > the actual, correct, political timezone is important, not just the GMT > offset. I am developing a website which would be accessed by members all over the world. They can exchange data having some time fields, say 'schedule for next meeting'. Whenever somebody feeds some time field, my application converts it to UTC and stores in the database. Later, when the data is to be displayed to some member, the application converts it to his local time, and displays the data. thanks Sanjay -- http://mail.python.org/mailman/listinfo/python-list
Re: pytz has so many timezones!
Thanks a lot, Guys. The immediate step I think to take is having two combo boxes (dividing the data by '/'). Thanks for enormous response and the valuable suggestions! Sanjay -- http://mail.python.org/mailman/listinfo/python-list
[ANN] FOSS Project for grabbing contacts from gmail, yahoo, rediff etc.
Hi All, Glad to announce a python open source project named ContactGrabber to grab the contact emails from gmail, yahoo, rediff etc. The project is hosted at http://code.google.com/p/pycontactgrabber/ and is also available at cheeseshop. It is now working fine for 'gmail', 'yahoo' and 'rediff'. I am not a python grandmaster and hence would deeply wish somebody taking the project forward. Sanjay -- http://mail.python.org/mailman/listinfo/python-list
Need paid support on pycontactgrabber
Hi All, We have initiated a project named ContactGrabber to grab the contact emails from gmail, yahoo, rediff etc. The project is hosted at http://code.google.com/p/pycontactgrabber/ and is also available at cheeseshop. It is now working fine for 'gmail', 'yahoo' and 'rediff'. We need it for a website and hence need to extend the project for Hotmail, WindowsLive, MSN, AOL etc. Interested developers can contact me at sanjay at radsolutions co in with indicative cost. thanks, Sanjay -- http://mail.python.org/mailman/listinfo/python-list
invite friends: contact list importing from hotmail, yahoo, gmail etc.
Hi All, I googled a lot trying to find out any FOSS python software for the above, but could not find one. Any pointers would be of vital help. thanks, Sanjay -- http://mail.python.org/mailman/listinfo/python-list
PyValentina 0.2.0 library documentation update on PyPI
Hi Everyone, I recently started working on Data Visualization. In one of my assignments, I want to use PyValentina 0.2.0 library. When I visited the https://pypi.org/project/PyValentina/ page and click on PyValentina Home Page link it give me a 404 error. After spending a little more time I come to know that PyValentina has now changed to the Petro library but the information and link are not updated everywhere. The PyValentina repository is also changed to Petro on GitHub. New link- https://fabricesalvaire.github.io/Patro/ https://github.com/FabriceSalvaire/Patro Old link- http://fabricesalvaire.github.io/PyValentina Can I add this issue to Github? -- https://mail.python.org/mailman/listinfo/python-list
Newbie: Python & Serial Port question
Am a python newbie. Does python have a native way to communicate with a PC serial port? I found that pyserial needs java. I am using Linux..CentOS 4.2, to be exact, no java installed and zilch/no/none/maybe never experience of java too. I have an application where I want to resd logs from the serial port of an EPABX and log them to a postgreSQL database. What's the best way to do this using python? Does anyone know of an existing software/python library/module for this? Please help. With best regards. Sanjay. -- http://mail.python.org/mailman/listinfo/python-list
HTML parsing/scraping & python
We are looking to select the language & toolset more suitable for a project that requires getting data from several web-sites in real- timehtml parsing/scraping. It would require full emulation of the browser, including handling cookies, automated logins & following multiple web-link paths. Multiple threading would be a plus but not requirement. Some solutions were suggested: Perl: LWP::Simple WWW::Mechanize HTML::Parser Curl & libcurl: Can you suggest solutions for python? Pros & Cons using Perl vs. Python? Why Python? Pointers to various other tools & their comparisons with python solutions will be most appreciated. Anyone who is knowledgeable about the application subject, please do share your knowledge to help us do this right. With best regards. Sanjay. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python script as SMTP server for outgoing e-mails?
On Tue, Jul 23, 2013 at 2:49 PM, Chris Angelico wrote: > Ah, there's a solution to this one. You simply use your own > envelope-from address; SPF shouldn't be being checked for the From: > header. Forwarding and using the original sender's address in the SMTP > 'MAIL FROM' command is forging mail from them, so it is correct for > that to be thrown out. The mail is coming from your own account, so > you put your address in it, and you might even be able to put an > uber-strict SPF record like "v=spf1 ip4:1.2.3.4 -all" which is quick > to process and guarantees that nobody can pretend to forward mail on > your behalf. The checks are for the *current connection*, not anything > earlier. > > ChrisA > Bit Late, but do check out http://www.openspf.org/FAQ/Forwarding Forwarding does get broken, but a partial solution in whitelisting is there, though too manual & therefore cumbersome. Another option http://www.openspf.org/SRS is there to be worked in conjunction with spf. There is a best spf practices guide on the site. And all this email authentication issue given on openspf.org makes an interesting read. Ciao. Sanjay. -- http://mail.python.org/mailman/listinfo/python-list
Error while installing PIL
Dear sir/madam I have already install python 2.7 64bit in my windows 8 machine but while installing PIL 1.1.7 for python 2.7 it says that "Python 2.7 required which was not found in the registry" Please help me sort out this problem Thanks in advance -- *Regards, Sanjay Madhikarmi Url: www.sanjaymadhikarmi.com.np <http://www.sanjaymadhikarmi.com.np>or www.sanjaymadhikarmi.com.np/isanj * -- https://mail.python.org/mailman/listinfo/python-list
Re: How can I find a freelance programmer?
Try this site I use them. You will make many freelancer contacts...some good some bad...don't pay without escrow but good jobs get done. Hope you will find it worthwhile. Best regards & good luck. Sanjay. On 2/15/06, Jorge Godoy <[EMAIL PROTECTED]> wrote: Charles <[EMAIL PROTECTED]> writes:> I am looking for a freelance Python programmer to create a cross-platform> application with wxPython.> Any idea where I could find one? Here? At Python-jobs? :-) At the wxPython mailing list?--Jorge Godoy <[EMAIL PROTECTED]>"Quidquid latine dictum sit, altum sonatur." - Qualquer coisa dita em latim soa profundo.- Anything said in Latin sounds smart.--http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Python program to run commands on cmd.exe from a tkinter GUI input box
Can anybody help or share a python code using Tkinter for opening cmd.exe and running command given from input box. For eg. when I run the code it will ask IP in an input box gui and ping response for that IP will be on cmd console -- https://mail.python.org/mailman/listinfo/python-list