Forum » Programiranje » Python končnica datoteke
Python končnica datoteke

filips ::
Imam to kodo:
V 67.vrstici želim s pomočjo funkcije, ki jo definiram v 1. vrstici ugotoviti kaj je končnica datoteke. Če ni exe, bi se morala izvesti prva koda, če ne pa druga.
Spremenljivke imam (pomembna je tista,ki je odebeljena):
versionVal='1.0',
descriptionVal='descriptionParm',
long_descriptionVal='long_descriptionParm',
urlVal='urlParm',
authorVal='authorParm',
author_emailVal='author_emailParm',
licenseVal='licenseParm',
keywordsVal='keywordsParm',
WindowsGuiInstallVal='installers',
WindowsCliInstallVal='WindowsCliInstallParm',
MacOsInstallVal='MacOsInstallParm',
LinuxInstallVal='LinuxInstallParm'
Čeprav installers nima končnice exe, se izvede koda, kot a jo ima. Kaj je narobe?
def extension(name): #težava je tukaj
return os.path.splitext(name)[1]
tb= traceback.extract_stack()
call=tb[4][0]
def callDir(file):
return os.path.dirname(os.path.realpath(file))
def urlCheck(url):
regex = re.compile(
_'^(?:http|ftp)s?://' # http:// or https:// #znak _ je na začetku vrstice namesto r ker mi drugače ne morem poslati
_'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?|' # domain... #znak _ je na začetku vrstice namesto r ker mi drugače ne morem poslati
_'localhost|' # localhost... #znak _ je na začetku vrstice namesto r ker drugače ne morem poslati
_'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip #znak _ je na začetku vrstice namesto r ker drugače ne morem poslati
_'(?::\d+)?' # optional port #znak _ je na začetku vrstice namesto r ker drugače ne morem poslati
_'(_?_:_/_?_|_[_/_?_]_\_S_+_?_:_/_?_|_[_/_?_]_\_S_+_)_$_', ___) #znak _ je na začetku vrstice namesto r in vsaka druga črka je _ in znak __ je namesto re.IGNORECASE ker drugače ne morem poslati
return url is not None and regex.search(url)
def title(*args):
'''print title'''
global status
global titleLines
titleLines=''
if status==1:
titleLines=args
def system():
'''return system platform'''
global status
if status==1:
return platform.system()
def relative():
return os.path.dirname(os.path.abspath(__file__))
def isdir(isdirfile):
return os.path.isdir(os.path.join(callDir(call),isdirfile))
def platforms():
global platforms
platforms=[]
if (WindowsCliInstallVal!=None or WindowsGuiInstallVal!=None) or (WindowsCliInstallVal!=None and WindowsGuiInstallVal!=None):
platforms+='Windows'
if LinuxInstallVal!=None:
platforms+='Linux'
if MacOsInstallVal!=None:
platforms+='MacOs'
for k in otherInstallVal:
platforms+=k
def install():
'''install program'''
global status
if status==1:
if title()!=None:
for line in titleLines:
print (line)
print ("{} Installer v{}\n".format(nameVal,versionVal))
global path
if system() is 'Windows':
if WindowsCliInstallVal and WindowsGuiInstallVal:
option=input('To install {} on Windows you have the following options:\n1) Windows Graphical Installer\n2) Windows Command line installer\n3) Exit\n\nSelect the desired option (1/2/3):'.format(nameVal))
if option==str(1):
print ('Starting Windows Graphical Installer')
if urlCheck(WindowsGuiInstallVal)!=None:
if extension(WindowsGuiInstallVal)!='.exe': #težava je tukaj
print (isdir(WindowsGuiInstallVal))
if isdir(WindowsGuiInstallVal)==True:
os.system('cp {} "/Program Files (x86)\\{}"'.format(WindowsGuiInstallVal,nameVal))
os.system('cp {} "/Program Files\\{}"'.format(WindowsGuiInstallVal,nameVal))
else:
os.system('start {}'.format(WindowsGuiInstallVal))
os.system('start {}'.format(WindowsGuiInstallVal))
else:
if extension(WindowsGuiInstallVal)!='.py':
os.system('start {}'.format(WindowsGuiInstallVal))
else:
install=__import__(WindowsCliInstallVal)
elif option==str(2):
print ('Starting Windows Command line Installer')
if urlCheck(WindowsGuiInstallVal)!=None:
os.system('start {}'.format(WindowsGuiInstallVal))
else:
if extension(WindowsGuiInstallVal)!='.py':
os.system('start {}'.format(WindowsGuiInstallVal))
else:
install=__import__(WindowsCliInstallVal)
else:
print("Abort.")
status==0
elif WindowsCliInstallVal:
print ('Starting Windows Command line Installer')
if urlCheck(WindowsGuiInstallVal)!=None:
os.system('start {}'.format(WindowsGuiInstallVal))
else:
if extension(WindowsGuiInstallVal)!='.py':
os.system('start {}'.format(WindowsGuiInstallVal))
else:
install=__import__(WindowsCliInstallVal)
elif WindowsGuiInstallVal:
print ('Starting Windows Graphical Installer')
if urlCheck(WindowsGuiInstallVal)!=None:
os.system('start {}'.format(WindowsGuiInstallVal))
else:
if extension(WindowsGuiInstallVal)!='.py':
os.system('start {}'.format(WindowsGuiInstallVal))
else:
install=__import__(WindowsCliInstallVal)
else:
print ("Program {} can't be installed on Windows")
elif system() is 'Linux':
print ('Starting Linux Installer')
if urlCheck(LinuxInstallVal)!=None:
os.system('x-www-browser {}'.format(LinuxInstallVal))
else:
install=__import__(WindowsCliInstallVal)
elif system() is 'Darwin':
if urlCheck(LinuxInstallVal)!=None:
os.system('open {}'.format(MacOsInstallVal))
else:
install=__import__(WindowsCliInstallVal)
else:
if otherInstallVal==None or otherInstallVal=={}:
print ("For your system program {} isn't available.".format(nameVal))
status==0
else:
for k, v in otherInstallVal.items():
if system() is k:
if urlCheck(v)!=None:
print ('Installation program for the system {} is available at this link: \n{}'.format(k,v))
else:
print ('Starting {}'.format(k))
install=__import__(v)
if system() not in otherInstallVal:
print ("For your system program {} isn't available.".format(nameVal))
status==0
V 67.vrstici želim s pomočjo funkcije, ki jo definiram v 1. vrstici ugotoviti kaj je končnica datoteke. Če ni exe, bi se morala izvesti prva koda, če ne pa druga.
Spremenljivke imam (pomembna je tista,ki je odebeljena):
versionVal='1.0',
descriptionVal='descriptionParm',
long_descriptionVal='long_descriptionParm',
urlVal='urlParm',
authorVal='authorParm',
author_emailVal='author_emailParm',
licenseVal='licenseParm',
keywordsVal='keywordsParm',
WindowsGuiInstallVal='installers',
WindowsCliInstallVal='WindowsCliInstallParm',
MacOsInstallVal='MacOsInstallParm',
LinuxInstallVal='LinuxInstallParm'
Čeprav installers nima končnice exe, se izvede koda, kot a jo ima. Kaj je narobe?
- spremenil: filips ()

frudi ::
Če ni exe, bi se morala izvesti prva koda, če ne pa druga.
Tole se zgleda ne sklada z zgornjo kodo. Katera "druga" koda bi se naj izvedla, če je exe?
1ACDoHVj3wn7N4EMpGVU4YGLR9HTfkNhTd... in case I've written something useful :)

Roadkill ::
Aja drugače pa nimam pojma kaj vrne "os.path.splitext(name)[1]"
Ampak če bi moral ugibat bi rekel, da vrne "exe" in ne ".exe"
Ampak če bi moral ugibat bi rekel, da vrne "exe" in ne ".exe"
Ü

frudi ::
os.path.splitext funkcija vrne tuple, katerega drugi element je končnica datoteke, vključno s piko. Oziroma prazen string, če podano ime datoteke nima končnice. Tukaj ne bi smel biti problem.
1ACDoHVj3wn7N4EMpGVU4YGLR9HTfkNhTd... in case I've written something useful :)
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | Fake traffic generatorOddelek: Omrežja in internet | 2360 (1556) | HotBurek |
» | Izdelava programa za delovanje v ozadjuOddelek: Programiranje | 1195 (788) | konspirator |
» | If stavek pingOddelek: Programiranje | 2111 (1576) | AndrejO |
» | [Python] Tutoriali za začetnika v Notepad++ (strani: 1 2 )Oddelek: Programiranje | 16939 (14033) | black ice |
» | sitemapOddelek: Izdelava spletišč | 1154 (1055) | rokpok |