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

693
Views
Al usar pathlib, se obtiene el error: TypeError: archivo no válido: PosixPath('example.txt')

Estoy usando el módulo pathlib de Python 3, así:

 from pathlib import Path filename = Path(__file__).parent / "example.txt" contents = open(filename, "r").read()

Pero me sale este error en algunas máquinas:

 TypeError: invalid file: PosixPath('example.txt')

Pero en mi máquina funciona.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

pathlib integra perfectamente con open solo en Python 3.6 y versiones posteriores. De las notas de lanzamiento de Python 3.6 :

La función integrada open() se actualizó para aceptar objetos os.PathLike , al igual que todas las funciones relevantes en los módulos os y os.path , y la mayoría de las demás funciones y clases en la biblioteca estándar.

Para que funcione en Python 3.5 y Python 3.6, simplemente convierta el objeto en una cadena:

 contents = open(str(filename), "r").read()
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!