piemaker100
Posts: 3
Joined: Sun Dec 30, 2018 2:37 pm

Help with shut.copy()

Sun Dec 30, 2018 2:54 pm

Hi
I am trying to copy a system file created when using 1 wire temperature sensors so that i can match it against a v-lookup function in a CSV file to print out the room name and not the 28-**** identifier code with the temperature reading
I want to copy the
/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves
system file at each reboot as this is when attached 1 wire temperature sensors (especially new ones) are attached
I think i have a syntax problem with the following
shutil.copy(/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves, /home/pi/Home_Control/w1_connected_ids.csv, , )
as it says that i have a syntax error near unexpected token ...
Do I need to use ' ' around the src and dst paths? or do i need a file type for the w1_master_slaves source file
Any help would be great
Thanks
The Piemaker

ghp
Posts: 1517
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Help with shut.copy()

Sun Dec 30, 2018 4:20 pm

See https://www.pythonforbeginners.com/os/p ... til-module, it might help you to find answers.

User avatar
thagrol
Posts: 3178
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Help with shut.copy()

Sun Dec 30, 2018 4:48 pm

piemaker100 wrote:
Sun Dec 30, 2018 2:54 pm
Do I need to use ' ' around the src and dst paths? or do i need a file type for the w1_master_slaves source file
Short answer: Yes.

Longer answer: You're passing strings so they have to be quoted. If you had assigned those strings to variables and were passing the variables those wouldn't need to be quoted but the assignment to the variables would.

For example:

Code: Select all

shutil.copy('source', 'dest')
source = 'foo'
dest = 'bar'
shutil.copy(foo, bar)
Arguing with strangers on the internet since 1993.

piemaker100
Posts: 3
Joined: Sun Dec 30, 2018 2:37 pm

Re: Help with shut.copy()

Sun Dec 30, 2018 6:56 pm

hi both
there seem to be 2 forms of shut.copy() one with 2 more arguments - i tried both
shutil.copy(src, dst, *, follow_symlinks=True)
i also tried using ' and " as the delimiters but got the same errors - anything obvious? do i need a file type for my source file eg .txt - just cannot see one in the FileManager window. the target file does not exist yet but that should not be the issue

pi@raspberrypicobham:~ $ shutil.copy("/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves","/home/pi/Home_Control/w1_connected_ids.csv",*,follow_symlinks=True)

bash: syntax error near unexpected token `"/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves","/home/pi/Home_Control/w1_connected_ids.csv"'

pi@raspberrypicobham:~ $ shutil.copy("/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves","/home/pi/Home_Control/w1_connected_ids.csv",*,follow_symlinks=True)

bash: syntax error near unexpected token `"/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves","/home/pi/Home_Control/w1_connected_ids.csv",*,follow_symlinks=True'

thanks

ghp
Posts: 1517
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Help with shut.copy()

Sun Dec 30, 2018 7:40 pm

Hello, obviously you try to use python commands from a command line. This is not the way python works. Usually you write the commands into a file ( something like sample.py) and execute this with an interpreter (on the command line type 'python3 sample.py' without the quotes).
There are some more options, of course.
Possibly you need to look for a python learning course, like https://www.programiz.com/python-programming

piemaker100
Posts: 3
Joined: Sun Dec 30, 2018 2:37 pm

Re: Help with shut.copy()

Sun Dec 30, 2018 10:46 pm

ghp

many thanks

it was not initially clear to me that this function was a high level function which could not be run from the terminal

i somehow assumed that file management would be like a mkdir command and be executable from the terminal

i now have it in a python file and it is working just fine

thanks for the tutorial link, i will try it. i have tried a number of sites but find many of them to be a little unstructured

i then need to get smart on Pandas!

mfg

Piemaker

Return to “Python”