Python Forum
Newbie Ubuntu script problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newbie Ubuntu script problem
#1
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.
Reply
#2
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.
Reply
#3
(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.
Reply
#4
Hi,

Can you remove all trailing extra lines in the code and check once?
Reply
#5
#!/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.
Reply
#6
yes, there was no proper closing brace')'.

Thanks for replying snippsat.
Reply
#7
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  very newbie problem on text file zapad 2 197 Apr-12-2024, 06:50 PM
Last Post: zapad
  Newbie first problem cima_hurdle 8 3,427 Feb-09-2022, 10:02 PM
Last Post: cima_hurdle
  Script stop work after 3 actioins - PLEASE WHERE IS THE PROBLEM? rondon442 0 1,557 Sep-27-2021, 05:40 PM
Last Post: rondon442
  Problem executing a script on a remote host tester_V 3 2,447 Sep-26-2021, 04:25 AM
Last Post: tester_V
  Python script in Ubuntu core Nithin_Kumar 1 3,364 May-11-2021, 01:14 AM
Last Post: Skaperen
  problem with sphinx and file directory in script kiyoshi7 0 2,285 Mar-11-2021, 03:52 PM
Last Post: kiyoshi7
  problem about slope in python script for bitcoin trading fisher_garry 1 2,501 Sep-02-2020, 01:39 PM
Last Post: fisher_garry
  Problem running script within console koepjo 3 9,896 Mar-26-2020, 07:11 AM
Last Post: koepjo
  Blender 2.49b not showing button when I run script on ubuntu like it does in windows? Vido 0 2,666 Dec-13-2019, 05:56 PM
Last Post: Vido
  Beginner problem in python script Cedmo 3 2,767 Jul-04-2019, 08:22 PM
Last Post: Cedmo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020