Python Forum

Full Version: Newbie Ubuntu script problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I decided for my first Python project I would make a program that broke up a text file into individual passwords that would be attempted on a rar file until the solution was found. This is what I came up with:

#!/usr/bin/env python3

import os

with open("home/me/pwds","r") as a:
for lines in a:
for words in lines.split():
os.system("unrar x -y -p{} /home/me/documents/target.rar".format(words)

The prog.py was given execute permissions, and it throws this error when run as "sudo python prog.py":

File "program.py", line 12

^
Syntax error: invalid syntax


Any help appreciated.
Your error says that it is on line 12, but you've posted fewer than 12 lines of Python. Please re-post with your whole code, and use code tags so that the indentation is not lost.
(Sep-24-2018, 03:25 AM)micseydel Wrote: [ -> ]Your error says that it is on line 12, but you've posted fewer than 12 lines of Python. Please re-post with your whole code, and use code tags so that the indentation is not lost.

I couldn't figure that out, I listed the whole code (indented properly. It was created in Gedit.
Hi,

Can you remove all trailing extra lines in the code and check once?
#!/usr/bin/env python3

import os

with open("home/me/pwds","r") as a:
    for lines in a:
        for words in lines.split():
            os.system("unrar x -y -p{} /home/me/documents/target.rar".format(words))
Last line your missing (words)).
Use subprocess instead os.system() security reasons and other problems.
Quote:os.system() and os.popen*() have been deprecated since Python 2.6 in favor of the subprocess module.
yes, there was no proper closing brace')'.

Thanks for replying snippsat.
(Sep-24-2018, 10:31 AM)Prabakaran141 Wrote: [ -> ]yes, there was no proper closing brace')'. Thanks for replying snippsat.

Ah thanks guys headed back in to work on it.