Python Forum
Newbie Ubuntu script problem - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Newbie Ubuntu script problem (/thread-13016.html)



Newbie Ubuntu script problem - Kloontor - Sep-24-2018

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.


RE: Newbie Ubuntu script problem - micseydel - Sep-24-2018

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.


RE: Newbie Ubuntu script problem - Kloontor - Sep-24-2018

(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.


RE: Newbie Ubuntu script problem - Prabakaran141 - Sep-24-2018

Hi,

Can you remove all trailing extra lines in the code and check once?


RE: Newbie Ubuntu script problem - snippsat - Sep-24-2018

#!/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.



RE: Newbie Ubuntu script problem - Prabakaran141 - Sep-24-2018

yes, there was no proper closing brace')'.

Thanks for replying snippsat.


RE: Newbie Ubuntu script problem - Kloontor - Sep-24-2018

(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.