Support Requests - CLICK TO READ BEFORE POSTING


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Stuck again, what's wrong?
#1

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:
# 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:
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
Reply
#2

Hello [member=6850]colin[/member] ,
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 Smile .
The Python, notice the line changes and indentations.

[Image: colin1.png]

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.

[Image: colin2.png]

How to run it in terminal

[Image: colin3.png]

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.
Reply
#3

need to install gedit.

[Image: col1.png]


[Image: col2.png]

Python looks fun
Reply
#4

[member=8093]Shanti[/member] great work, glad you liked Python 8)
Reply
#5

Gedit up now  Smile  thanks for template help.


[Image: Screenshot_2018_09_27_17_42_28.png]
Reply
#6

You are welcome [member=8093]Shanti[/member]  Smile It's looking good.
Reply
#7

Thanks for the help once again bitsnpcs.

Old and getting even older lol
Reply
#8

You are Welcome Colin  Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)