You are Here:
Linux Lite 4.2 Beta has been released. See the Release Announcements Section.




Stuck again, what's wrong?

Author (Read 907 times)

0 Members and 1 Guest are viewing this topic.

Stuck again, what's wrong?
« on: July 13, 2018, 05:50:59 AM »
 

colin

  • Occasional Poster
  • **
  • 54
    Posts
  • Country: wales
  • Reputation: 4
  • Linux Lite Member

  • Linux Lite: 3.8 64bit
I'm trying to learn Python3 from the book Learn Python 3 the Hard Way and find it hard going especially when the code keeps on displaying an error. Take for instance, exercise 20.
Code: [Select]
# ex20: Functions and Files   
   from sys import argv   
   script, input_file = argv   
   def print_all(f):       print(f.read())   
   def rewind(f):       f.seek(0)   
def print_a_line(line_count, f):       print(line_count, f.readline())   
   current_file = open(input_file)   
   print("First let's print the whole file:\n")   
   print_all(current_file)   
   print("Now let's rewind, kind of like a tape.")   
   rewind(current_file)   
   print("Let's print three lines:")   
   current_line = 1   print_a_line(current_line, current_file)   
   current_line = current_line + 1   print_a_line(current_line, current_file)   
   current_line = current_line + 1   print_a_line(current_line, current_file)
I keep getting the following error
Code: [Select]
colin@my_new_LinuxLite4.0:~$ python3 ~/python_exp/ex20.pyTraceback (most recent call last):    File "/home/colin/python_exp/ex20.py", line 7, in <module>       script, input_file = argvValueError: not enough vales to unpack (expected 2, got 1)colin@my_new_LinuxLite4.0:~$
I've come across this error on a previous exercise but sadly misplaced my notes on how to remedy the error. Can someone help me please. 
Old and getting even older lol
 


Re: Stuck again, what's wrong?
« Reply #1 on: September 24, 2018, 05:08:56 PM »
 

bitsnpcs

  • Platinum Level Poster
  • **********
  • 2687
    Posts
  • Country: ie
  • Reputation: 277

  • Linux Lite: 3.0 64bit
Hello @colin ,
it looks like you are running the file incorrectly as you are not specifying the command in terminal.
I do not have the Python3 book only the Python2, I had a try at this one though to help :) .
The Python, notice the line changes and indentations.



The test.txt file used (contents are his words not mine) from an exercise in the Python2 book, I just renamed it to use for this try.



How to run it in terminal



On highlight in terminal see #1, #2 and #3 above, these are the components of the command that you need.
For #2 you can either cd to the directory containing your Python files, or you can enter in your Path as previously. I just put it in Home directory as its temporary for this post.
#3 is what you have missed in the terminal command ?  or it is in another folder than the Python file is.
Last Edit: September 24, 2018, 05:22:54 PM by bitsnpcs
I use no computer in work, I am just a home user, at beginner/learning Linux stage.
Trying to join in with community and assist where it may be possible :)
 

Re: Stuck again, what's wrong?
« Reply #2 on: September 25, 2018, 02:23:38 PM »
 

Shanti

  • New to Forums
  • *
  • 14
    Posts
  • Country: gb
  • Reputation: 7
  • Linux Lite Member

  • Linux Lite: 4.0 64bit

  • CPU: Core i5 vPro

  • MEMORY: 16Gb
need to install gedit.






Python looks fun
women's instructor
 

Re: Stuck again, what's wrong?
« Reply #3 on: September 25, 2018, 02:31:03 PM »
 

bitsnpcs

  • Platinum Level Poster
  • **********
  • 2687
    Posts
  • Country: ie
  • Reputation: 277

  • Linux Lite: 3.0 64bit
@Shanti great work, glad you liked Python 8)
I use no computer in work, I am just a home user, at beginner/learning Linux stage.
Trying to join in with community and assist where it may be possible :)
 

Re: Stuck again, what's wrong?
« Reply #4 on: September 27, 2018, 12:51:59 PM »
 

Shanti

  • New to Forums
  • *
  • 14
    Posts
  • Country: gb
  • Reputation: 7
  • Linux Lite Member

  • Linux Lite: 4.0 64bit

  • CPU: Core i5 vPro

  • MEMORY: 16Gb
Gedit up now  :)  thanks for template help.


women's instructor
 

Re: Stuck again, what's wrong?
« Reply #5 on: September 27, 2018, 03:58:36 PM »
 

bitsnpcs

  • Platinum Level Poster
  • **********
  • 2687
    Posts
  • Country: ie
  • Reputation: 277

  • Linux Lite: 3.0 64bit
You are welcome @Shanti  :) It's looking good.
I use no computer in work, I am just a home user, at beginner/learning Linux stage.
Trying to join in with community and assist where it may be possible :)
 


Tags:
 


Linux Lite 4.2 Beta has been released. See the Release Announcements Section.