diff --git a/par2ools/par2.py b/par2ools/par2.py
index <HASH>..<HASH> 100644
--- a/par2ools/par2.py
+++ b/par2ools/par2.py
@@ -75,7 +75,7 @@ class Par2File(object):
         else:
             self.contents = obj_or_path.read()
             if getattr(obj_or_path, 'name', None):
-                self.path = f.name
+                self.path = obj_or_path.name
         self.packets = self.read_packets()
 
     def read_packets(self):
Fix opening by file object

Fix error `UnboundLocalError: local variable 'f' referenced before assignment`