sábado, 24 de junio de 2017

PYTHON HEAD FIRST, FIRST STEPS SESSION2







>>> import os
>>> os.getcwd
<built-in function getcwd>
>>> os.chdir('C:\hf\read')
Traceback (most recent call last):
  File "<pyshell#76>", line 1, in <module>
    os.chdir('C:\hf\read')
OSError: [WinError 123] El nombre de archivo, el nombre de directorio o la sintaxis de la etiqueta del volumen no son correctos: 'C:\\hf\read'
>>> os.chdir('../hf/read')
Traceback (most recent call last):
  File "<pyshell#77>", line 1, in <module>
    os.chdir('../hf/read')
FileNotFoundError: [WinError 3] El sistema no puede encontrar la ruta especificada: '../hf/read'
>>> os.getcwd
<built-in function getcwd>
>>> os.getcwd()
'C:\\Users\\rober\\AppData\\Local\\Programs\\Python\\Python35'
>>> os.chdir('../hf/read')
Traceback (most recent call last):
  File "<pyshell#80>", line 1, in <module>
    os.chdir('../hf/read')
FileNotFoundError: [WinError 3] El sistema no puede encontrar la ruta especificada: '../hf/read'
>>> os.chdir('/hf/read')
Traceback (most recent call last):
  File "<pyshell#81>", line 1, in <module>
    os.chdir('/hf/read')
FileNotFoundError: [WinError 3] El sistema no puede encontrar la ruta especificada: '/hf/read'
>>> os.chdir('./hf/read')
>>> os.getcwd()
'C:\\Users\\rober\\AppData\\Local\\Programs\\Python\\Python35\\hf\\read'
>>> data = open('sketch.txt')
>>> print(data.readline(), end='')
Man: Is this the right room for an argument?
>>> print(data.readline(), end='')
Other Man: I've told you once.
>>> data.seek(0)
0
>>> for each_line in data:
print(each_line, ends='')


Traceback (most recent call last):
  File "<pyshell#90>", line 2, in <module>
    print(each_line, ends='')
TypeError: 'ends' is an invalid keyword argument for this function
>>> for each_line in data:
print(each_line, end='')


Other Man: I've told you once.
Man: No you haven't!
Other Man: Yes I have.
Man: When?
Other Man: Just now.
Man: No you didn't!
Other Man: Yes I did!
Man: You didn't!
Other Man: I'm telling you, I did!
Man: You did not!
Other Man: Oh I'm sorry, is this a five minute argument, or the full half hour?
Man: Ah! (taking out his wallet and paying) Just the five minutes.
Other Man: Just the five minutes. Thank you.
Other Man: Anyway, I did.
Man: You most certainly did not!
Other Man: Now let's get one thing quite clear: I most definitely told you!
Man: Oh no you didn't!
Other Man: Oh yes I did!
Man: Oh no you didn't!
Other Man: Oh yes I did!
Man: Oh look, this isn't an argument!
(pause)
Other Man: Yes it is!
Man: No it isn't!
(pause)
Man: It's just contradiction!
Other Man: No it isn't!
Man: It IS!
Other Man: It is NOT!
Man: You just contradicted me!
Other Man: No I didn't!
Man: You DID!
Other Man: No no no!
Man: You did just then!
Other Man: Nonsense!
Man: (exasperated) Oh, this is futile!!
(pause)
Other Man: No it isn't!
Man: Yes it is!
>>> data.close()
>>> data = open('sketch.txt')
>>> for each_line in data:
(role,line_spoken)=each_line.split(':')
print(role, end='')
print(' said: ', end='')
print(line_spoken, end='')


Man said:  Is this the right room for an argument?
Other Man said:  I've told you once.
Man said:  No you haven't!
Other Man said:  Yes I have.
Man said:  When?
Other Man said:  Just now.
Man said:  No you didn't!
Other Man said:  Yes I did!
Man said:  You didn't!
Other Man said:  I'm telling you, I did!
Man said:  You did not!
Other Man said:  Oh I'm sorry, is this a five minute argument, or the full half hour?
Man said:  Ah! (taking out his wallet and paying) Just the five minutes.
Other Man said:  Just the five minutes. Thank you.
Other Man said:  Anyway, I did.
Man said:  You most certainly did not!
Traceback (most recent call last):
  File "<pyshell#98>", line 2, in <module>
    (role,line_spoken)=each_line.split(':')
ValueError: too many values to unpack (expected 2)
>>> help(each_line.split)
Help on built-in function split:

split(...) method of builtins.str instance
    S.split(sep=None, maxsplit=-1) -> list of strings
 
    Return a list of the words in S, using sep as the
    delimiter string.  If maxsplit is given, at most maxsplit
    splits are done. If sep is not specified or is None, any
    whitespace string is a separator and empty strings are
    removed from the result.

>>> data = open('sketch.txt')
>>> for each_line in data:
try:
   (role,line_spoken)=each_line.split(':')
    print(role, end='')
    print(' said: ', end='')
    print(line_spoken, end='')
 
SyntaxError: unexpected indent
>>> for each_line in data:
try:
(role,line_spoken)=each_line.split(':')
print(role, end='')
print(' said: ', end='')
         print(line_spoken, end='')
       
SyntaxError: expected an indented block
>>> for each_line in data:
        try:
   (role,line_spoken)=each_line.split(':')
    print(role, end='')
    print(' said: ', end='')
             print(line_spoken, end='')
           
SyntaxError: inconsistent use of tabs and spaces in indentation
>>> for each_line in data:
try:
(role,line_spoken)=each_line.split(':')
print(role, end='')
print(' said: ', end='')
print(' said: ', end='')

except:
pass
data.close()
SyntaxError: invalid syntax
>>>
>>> for each_line in data:
try:
(role,line_spoken)=each_line.split(':')
print(role, end='')
print(' said: ', end='')
print(' said: ', end='')
        except:
pass
data.close()
SyntaxError: inconsistent use of tabs and spaces in indentation
>>> for each_line in data:
try:
(role,line_spoken)=each_line.split(':')
print(role, end='')
print(' said: ', end='')
print(' said: ', end='')
except:
pass


Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Other Man said:  said: Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said:
>>> data = open('sketch.txt')
>>> for each_line in data:
try:
(role,line_spoken)=each_line.split(':')
print(role, end='')
print(' said: ', end='')
print(' said: ', end='')
except:
pass


Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Other Man said:  said: Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said: Other Man said:  said: Man said:  said:
>>> for each_line in data:
try:
(role,line_spoken)=each_line.split(':')
print(role, end='')
print(' said: ', end='')
print(' said: ', end='')
except:
pass


>>>
>>>

data = open('sketch.txt')
   for each_line in data:
(role,line_spoken)=each_line.split(':')
print(role, end='')
print(' said: ', end='')
print(line_spoken, end='')

SyntaxError: multiple statements found while compiling a single statement
>>> data = open('sketch.txt')
   for each_line in data:
(role,line_spoken)=each_line.split(':')
print(role, end='')
print(' said: ', end='')
print(line_spoken, end='')

SyntaxError: multiple statements found while compiling a single statement
>>> data = open('sketch.txt')

 
>>> for each_line in data:
(role,line_spoken)=each_line.split(':')
print(role, end='')
print(' said: ', end='')
print(line_spoken, end='')


Man said:  Is this the right room for an argument?
Other Man said:  I've told you once.
Man said:  No you haven't!
Other Man said:  Yes I have.
Man said:  When?
Other Man said:  Just now.
Man said:  No you didn't!
Other Man said:  Yes I did!
Man said:  You didn't!
Other Man said:  I'm telling you, I did!
Man said:  You did not!
Other Man said:  Oh I'm sorry, is this a five minute argument, or the full half hour?
Man said:  Ah! (taking out his wallet and paying) Just the five minutes.
Other Man said:  Just the five minutes. Thank you.
Other Man said:  Anyway, I did.
Man said:  You most certainly did not!
Traceback (most recent call last):
  File "<pyshell#136>", line 2, in <module>
    (role,line_spoken)=each_line.split(':')
ValueError: too many values to unpack (expected 2)
>>> for each_line in data:
try:
(role,line_spoken)=each_line.split(':')
print(role, end='')
print(' said: ', end='')
print(' said: ', end='')
except:
pass

No hay comentarios:

Publicar un comentario

Blogger Widgets