My first Python program :) optimize code?

Questions about programming languages and debugging
Post Reply
xtheblack9x
suck-o-fied!
suck-o-fied!
Posts: 99
Joined: 15 Jan 2006, 17:00
15
Location: USA

My first Python program :) optimize code?

Post by xtheblack9x »

ya i wrote my first python program thats almost useful (that wasn't copyed out of a book). Its only really about half way done though. :lol:

this program right now just takes a path and a key word you want and makes out the the text you would need to put in a .reg file to make a new run command shortcut.

in the future i want to put a gui to it and make it change the registry itself not just give you the text, but i have to read alot more for that.

I do need some help optimizing what i have though. Take note this is my first python program and i don't have all that much programing experance. heres what i have.

Code: Select all

#inputs
pathp = raw_input('Program Path: ')
namep = raw_input('Program Command: ')

#convert to list
pathp = list(pathp)

#make double slashes for registry format
slash1 = pathp.index('\\')
pathp.insert(slash1 , '\\')


if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3


if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3

if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')
if '\\' in pathp[slash1 :]: slash1 = slash3


#convert back to string
pathp = ''.join(pathp)

#output
print " "
print r"Windows Registry Editor Version 5.00"
print " "
print "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" + namep + '.exe' + ']'
print '@="' + pathp + '"'
print ' '
input('press enter to end')
ok ha ha ha ya i use the same exact 5 lines like 30 times and all to add double back slashes instead of one. is there a way i can just use the 5 lines once and multiply it buy 30? or am i going about this fully the wrong way and this code is way off of proper programing.

if everyone programed like this are computer world would be a mess.

User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1613
Joined: 28 Aug 2005, 16:00
15

Well You could try

Post by maboroshi »

Hey you could try a for loop

Code: Select all

for i in range(30):
    if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
    if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
    if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
    if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')

    if '\\' in pathp[slash1 :]: slash1 = slash3
don't know if It works correctly by doing this as I am not entirely sure about how the program works

but try that and let me know

xtheblack9x
suck-o-fied!
suck-o-fied!
Posts: 99
Joined: 15 Jan 2006, 17:00
15
Location: USA

Re: Well You could try

Post by xtheblack9x »

Maboroshi wrote:Hey you could try a for loop

Code: Select all

for i in range(30):
    if '\\' in pathp[slash1 + 1 :]: slash1 = slash1 + 2
    if '\\' in pathp[slash1 :]: slash2 = pathp[slash1 :].index('\\')
    if '\\' in pathp[slash1 :]: slash3 = slash2 + slash1
    if '\\' in pathp[slash1 :]: pathp.insert(slash3 , '\\')

    if '\\' in pathp[slash1 :]: slash1 = slash3
don't know if It works correctly by doing this as I am not entirely sure about how the program works

but try that and let me know
thanks but that didn't work wouldn't i have to specify like in rackets or something that tells the computer what its repeating and where it stops repeating?

User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1613
Joined: 28 Aug 2005, 16:00
15

No

Post by maboroshi »

Python use Indentation to determine its code blocks so brackets are not nessaccry I would suggest using idle the built in python ide cause it indents code automatically for you

but I was playing with your code and I believe the result is the same with what I have done to optomize your code (but I am not sure) But congratulations on writing your first program

took me years to figure out how to write my firts program lol

Code: Select all



#inputs
pathp = raw_input('Program Path: ')
namep = raw_input('Program Command: ')

#convert to list
pathp = str(pathp)

#make double slashes for registry format
pathp = '//'.join(pathp.split('/'))

#output
print " "
print r"Windows Registry Editor Version 5.00"
print " "
print "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" + namep + '.exe' + ']'
print '@="' + pathp + '"'
print ' '
input('press enter to end')



xtheblack9x
suck-o-fied!
suck-o-fied!
Posts: 99
Joined: 15 Jan 2006, 17:00
15
Location: USA

Re: No

Post by xtheblack9x »

ya for me thats just outputing single slashes. well this is my first python program but actouly i have made a few small games with flash action scripting. and i have done some combo .reg and .bat files to do some things. so i suppose i have a little programing experance but not much.

Post Reply