Getting the file path correct

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
gckhomes

Getting the file path correct

Post by gckhomes »

I had a developer write a simple python script but am unable to get it to run. I believe it is due to the file path. Does anyone see why the notice_parser.py is giving me the syntax error? I have been trying for days to get this to work. Thank you in advance.

gck@gck ~/parser_home $ tree
.
├── business_observer
│   ├── 2016-10-07-Hillsborough.pdf
│   └── bo pine100716.pdf
├── freepress
│   └── hillsborough
│   ├── fphills10012016.pdf
│   ├── fphills8272016.pdf
│   ├── fphills9172016.pdf
│   └── fphills932016.pdf
├── notice_parser.py
└── parse_freepress.py

3 directories, 8 files
gck@gck ~/parser_home $ python notice_parser.py
File "notice_parser.py", line 83
first_name, *rest = owner.split(' ')
^
SyntaxError: invalid syntax
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
deepakdeshp
Level 20
Level 20
Posts: 12333
Joined: Sun Aug 09, 2015 10:00 am

Re: Getting the file path correct

Post by deepakdeshp »

Hello,
The file path looks cortect as the ereor message is not file not found.
A file in your home dirextory is referenced as ./file
To know more about the naming convention see
http://teaching.idallen.com/cst8207/13w ... names.html
If I have helped you solve a problem, please add [SOLVED] to your first post title, it helps other users looking for help.
Regards,
Deepak

Mint 21.1 Cinnamon 64 bit with AMD A6 / 8GB
Mint 21.1 Cinnamon AMD Ryzen3500U/8gb
lmuserx4849

Re: Getting the file path correct

Post by lmuserx4849 »

gckhomes wrote:I had a developer write a simple python script but am unable to get it to run.
...
gck@gck ~/parser_home $ python notice_parser.py
File "notice_parser.py", line 83
first_name, *rest = owner.split(' ')
^
SyntaxError: invalid syntax
Is that the entire output from notice_parser.py. If you are running for the first time, contact dev to correct the error on line 83 and/or provide error handling.

Without seeing the code, knowing the purpose, and the program is new, a couple of initial thoughts:

1. Was it written for python 2 or 3? You'll have to ask the dev that question.

Type python --version and python3 --version

Trypython3 notice_parser.py

If there is a line in notice_parser.py at the top or right after the top comments that looks like the line below, you don't need to type python, just the program name. The program will need to be executable (i.e., chmod u+x). If the program is in a directory in your path (echo $PATH), just type the pgmName. Otherwise change directory and type ./pgmName or type full-qualified pgmName. Most people add $HOME/bin at the front of their path.

#!/usr/bin/env python (this could be python3 too).

2. End-of-line character - Was it written on MS and now running on a Linux.

Do a cat -A notice_parser.py and if you see "^M$", or file notice_parser.py and see CRLF line terminators, backup notice_parser.py and run dos2unix.

I'm leaning toward #1, but I could be wrong ;-)
User avatar
xenopeek
Level 25
Level 25
Posts: 29459
Joined: Wed Jul 06, 2011 3:58 am

Re: Getting the file path correct

Post by xenopeek »

lmuserx4849 wrote:Was it written for python 2 or 3?
This. Linux Mint 17.3 and earlier have Python 2 as the default when you call python. Linux Mint 18 and later have (finally!) Python 3 instead as the default when you call python. There is syntax difference so it can cause such errors. Call the specific version and use python2 or python3 instead of python.
Image
Locked

Return to “Scripts & Bash”