Jump to content
iusty2417

tabel in python

Recommended Posts

Buna. Am un fisier txt cu Titlu, autor, editura, cuvinte cheie. Caut un autor, iar cartile acestuia vreau sa apara sub forma unui tabel in python.

a=open("1.txt)

text=input("Autor:")

for line in a:

if text in line:

print (line)

Cum as putea sa fac sa-mi apara intr-un tabel de forma:

=========================================================

Titlu | Autor | Editura | An |

=========================================================

Amintiri din copilarie | Ion Creanga | Academiei Romane | 1991 |

Link to comment
Share on other sites

Nu am apucat sa fac si un test, dar cam asa ar arata.


import os
with open('1.txt','rU') as af: authors = af.read().splitlines()
keyw = raw_input('Introduceti Un Cuvant Cheie: ')

for author in authors:
if keyw in author:
os.system('cls' if os.name == 'nt' else 'clear')
print '================================================== =======\n'
print 'Titlu | Autor | Editura | An |\n'
print '================================================== =======\n'
titlu = author.split(", ")[0]
autor = author.split(", ")[1]
editura = author.split(", ")[2]
an = author.split(", ")[3]
print titlu+' | ' +autor+' | ' +editura+' | ' +an+' |\n'

Daca vrei sa efectuezi cautari mai multe, bagi for-ul intr-un while infinit, si iesi din el daca keyw este Quit. Trebuie sa bagi keyw in for in cazul asta.

Link to comment
Share on other sites

mii de scuze. am incercat, merge, dar in momentul in care introduc un cuvant ce se afla in mai multe linii imi tot apare tabelul de cate ori este intalnit. daca am 3 carti, imi apar 3 tabele si in fiecare tabel o carte. as vrea sa apara toate cartile in acelasi tabel.

pentru un om care nu a facut niciodata informatica e destul de greu

Edited by Usr6
merged
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...