View unanswered posts | View active topics It is currently Thu Oct 31, 2024 11:54 pm



Post new topic Reply to topic  [ 2 posts ] 
 'Standard' duplicate imports 
Author Message
User avatar

Joined: Wed Dec 09, 2009 9:39 pm
Posts: 712
Post 'Standard' duplicate imports
I had to point this out hoping to get some feedback/. Below is the source of the start_client.py for Standard. My question is .. Why import all of os, end then import os.path? You don't even use the import 'path', you use os.path.

Another question, why import 100% of os when you are using chdir, and path? Same thing with sys, why import all of it when all you use is argv?

The duplicate made me curious.

Code:
#!/usr/bin/env python

import sys
import os, os.path
import runpy

runpy.run_module('updater.gui', run_name='__main__', alter_sys=True)

import pyver
pyver.checkPyVersion()

from orpg.orpg_wx import *
import orpg.main
from orpg.tools.orpg_log import logger

if __name__ == "__main__":
os.chdir(os.path.abspath(os.path.dirname(sys.argv[0])))
if WXLOADED:
mainapp = orpg.main.orpgApp(0)
mainapp.MainLoop()
else:
logger.exception("You really really need wx!")

_________________
I ate your Death Knell.
The Traipse Movement
Please show your support for Traipse OpenRPG http://www.facebook.com/MadMathLabs
Send me Traipse OpenRPG Ideas, Bugs, Complaints, Praises here: https://getsatisfaction.com/mml


Tue Feb 09, 2010 11:43 pm
Profile YIM WWW

Joined: Sat Dec 12, 2009 4:14 pm
Posts: 9
Post Re: 'Standard' duplicate imports
the import os, os.path is a hold over from python 2.3 where you could not just do
Code:
import os
os.path.blabla


As for why importing all of sys and os, because it is faster and less error prone the importing each individual item from the module when using builtin modules where you are likely to use many different methods / submodules like sys, os, time, re, etc. Also it is very good for name-spacing so I dont accidentally overwrite a method / attribute by doing

Code:
from os.path import dirname
...
dirname = "/usr/local/bin/bla"
...
dirname(something) #Exception because I messed up the os.path.dirname method


Mon Mar 22, 2010 7:55 pm
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.