Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
Repita los resultados de Path.glob() (Pathlib)

Estoy luchando con el resultado del método Path.glob() del módulo Pathlib en Python 3.6.

 from pathlib import Path dir = Path.cwd() files = dir.glob('*.txt') print(list(files)) >> [WindowsPath('C:/whatever/file1.txt'), WindowsPath('C:/whatever/file2.txt')] for file in files: print(file) print('Check.') >>

Evidentemente, glob encontró archivos, pero el ciclo for no se ejecuta. ¿Cómo puedo recorrer los resultados de una búsqueda pathlib-glob?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

>>> from pathlib import Path >>> >>> dir = Path.cwd() >>> >>> files = dir.glob('*.txt') >>> >>> type(files) <class 'generator'>

Aquí, los files son un generator , que solo se pueden leer una vez y luego se agotan. Entonces, cuando intentes leerlo por segunda vez, no lo tendrás.

 >>> for i in files: ... print(i) ... /home/ahsanul/test/hello1.txt /home/ahsanul/test/hello2.txt /home/ahsanul/test/hello3.txt /home/ahsanul/test/b.txt >>> # let's loop though for the 2nd time ... >>> for i in files: ... print(i) ... >>>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!