Re: absolute path to a file
On Fri, 16 Aug 2019 09:00:38 +1000 Cameron Simpson wrote: > On 15Aug2019 22:52, Manfred Lotz wrote: > >I did this: > >from pathlib import Path > >abs_myfile = Path('./myfile').resolve() > >which worked fine for me. > > There is also os.path.realpath(filename) for this purpose. In modern > Python that also accepts a Pathlike object. Thanks for this. I changed my code to use your suggestion which seems to be better for the situation where I used resolve() before. -- Manfred -- https://mail.python.org/mailman/listinfo/python-list
Re: absolute path to a file
On 15Aug2019 22:52, Manfred Lotz wrote: On Thu, 15 Aug 2019 22:00:17 +0200 Paul St George wrote: But I want an absolute path such as: ---Plane uses image01.tif saved at /Users/Lion/Desktop/test8/image01.tif ---Plane uses image02.tif saved at /Users/Lion/Desktop/images/image02.tif If it is relevant, my files are on a Mac. Hence the escaped forward slash. You don't need to double the leading slash on a Mac. On 15Aug2019 22:52, Manfred Lotz wrote: I did this: from pathlib import Path abs_myfile = Path('./myfile').resolve() which worked fine for me. There is also os.path.realpath(filename) for this purpose. In modern Python that also accepts a Pathlike object. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: absolute path to a file
On Thu, 15 Aug 2019 22:00:17 +0200 Paul St George wrote: > Can someone please tell me how to get the absolute path to a file? I > have tried os.path.abspath. In the code below I have a problem in the > final line (15). > > # > |import bpy|| > ||import os|| > || > ||texture_list = []|| > || > ||with open(os.path.splitext(bpy.data.filepath)[0] + ".txt", "w") as > outstream:|| > || > || > || for obj in bpy.context.scene.objects:|| > || for s in obj.material_slots:|| > || if s.material and s.material.use_nodes:|| > || for n in s.material.node_tree.nodes:|| > || if n.type == 'TEX_IMAGE':|| > || texture_list += [n.image]|| > ||print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, > 'which is at', os.path.abspath(n.image.filepath), file=outstream)|| > |# > > This gives me: > ---Plane uses image01.tif saved at //image01.tif which is > at //image01.tif ---Plane uses image02.tif saved > at //../images/image02.tif which is at //images/image02.tif > > But I want an absolute path such as: > ---Plane uses image01.tif saved > at /Users/Lion/Desktop/test8/image01.tif ---Plane uses image02.tif > saved at /Users/Lion/Desktop/images/image02.tif > > If it is relevant, my files are on a Mac. Hence the escaped forward > slash. > I did this: from pathlib import Path abs_myfile = Path('./myfile').resolve() which worked fine for me. -- Manfred -- https://mail.python.org/mailman/listinfo/python-list
Re: absolute path to a file
On Fri, Aug 16, 2019 at 6:01 AM Paul St George wrote: > > Can someone please tell me how to get the absolute path to a file? I > have tried os.path.abspath. In the code below I have a problem in the > final line (15). > > # > |import bpy|| > ||import os|| > || > ||texture_list = []|| > || > ||with open(os.path.splitext(bpy.data.filepath)[0] + ".txt", "w") as > outstream:|| > || > || > || for obj in bpy.context.scene.objects:|| > ||for s in obj.material_slots:|| > ||if s.material and s.material.use_nodes:|| > ||for n in s.material.node_tree.nodes:|| > ||if n.type == 'TEX_IMAGE':|| > ||texture_list += [n.image]|| > ||print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, 'which > is at', os.path.abspath(n.image.filepath), file=outstream)|| > |# > > This gives me: > ---Plane uses image01.tif saved at //image01.tif which is at //image01.tif > ---Plane uses image02.tif saved at //../images/image02.tif which is at > //images/image02.tif > > But I want an absolute path such as: > ---Plane uses image01.tif saved at /Users/Lion/Desktop/test8/image01.tif > ---Plane uses image02.tif saved at /Users/Lion/Desktop/images/image02.tif > > If it is relevant, my files are on a Mac. Hence the escaped forward slash. > I don't understand the meaning of "escaped forward slash". What does that mean, and how does it affect your path names? -- not a Mac person -- ChrisA -- https://mail.python.org/mailman/listinfo/python-list
absolute path to a file
Can someone please tell me how to get the absolute path to a file? I have tried os.path.abspath. In the code below I have a problem in the final line (15). # |import bpy|| ||import os|| || ||texture_list = []|| || ||with open(os.path.splitext(bpy.data.filepath)[0] + ".txt", "w") as outstream:|| || || || for obj in bpy.context.scene.objects:|| || for s in obj.material_slots:|| || if s.material and s.material.use_nodes:|| || for n in s.material.node_tree.nodes:|| || if n.type == 'TEX_IMAGE':|| || texture_list += [n.image]|| ||print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, 'which is at', os.path.abspath(n.image.filepath), file=outstream)|| |# This gives me: ---Plane uses image01.tif saved at //image01.tif which is at //image01.tif ---Plane uses image02.tif saved at //../images/image02.tif which is at //images/image02.tif But I want an absolute path such as: ---Plane uses image01.tif saved at /Users/Lion/Desktop/test8/image01.tif ---Plane uses image02.tif saved at /Users/Lion/Desktop/images/image02.tif If it is relevant, my files are on a Mac. Hence the escaped forward slash. -- Paul St George http://www.paulstgeorge.com http://www.devices-of-wonder.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Create multiple sqlite tables, many-to-many design
Chris Angelico wrote: > On Thu, Aug 15, 2019 at 7:41 PM Gregory Ewing > wrote: >> >> Chris Angelico wrote: >> > I prefer to say "Trails" for the table, and "Trail" would then refer >> > to a single row from that table. >> >> That makes sense for a data structure in your program that contains a >> collection of rows. But I've come to the view that SQL tends to read >> better if the names of the database tables are singular, because in SQL >> you're writing assertions about individual rows, not the tables in >> their entirety. >> >> So I would write something like >> >> select T.name, T.id from Trail T >> >> but I would assign the resulting list of rows to a variable named >> "trails" in my program. >> > > You're selecting from a collection of trails. I don't see a conflict > here. It's the same as taking a list of values and then filtering it - > even though assertions are made about individuals, you are filtering > the entire list: > > early_things = [thing for thing in things if thing.name < 'M'] If list comprehensions were like sql queries then the above would be early_things = [things.* from things where things.name < "M"] That doesn't read well as the condition works on one thing at a time. However, I'm so used to select things.* from things where things.name < "M" in the sql context that I still prefer it. Also, in simple queries you can omit the table name. -- https://mail.python.org/mailman/listinfo/python-list
Re: Create multiple sqlite tables, many-to-many design
On Thu, Aug 15, 2019 at 7:41 PM Gregory Ewing wrote: > > Chris Angelico wrote: > > I prefer to say "Trails" for the table, and "Trail" would then refer > > to a single row from that table. > > That makes sense for a data structure in your program that contains a > collection of rows. But I've come to the view that SQL tends to read > better if the names of the database tables are singular, because in SQL > you're writing assertions about individual rows, not the tables in > their entirety. > > So I would write something like > > select T.name, T.id from Trail T > > but I would assign the resulting list of rows to a variable named > "trails" in my program. > You're selecting from a collection of trails. I don't see a conflict here. It's the same as taking a list of values and then filtering it - even though assertions are made about individuals, you are filtering the entire list: early_things = [thing for thing in things if thing.name < 'M'] ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Create multiple sqlite tables, many-to-many design
Chris Angelico wrote: I prefer to say "Trails" for the table, and "Trail" would then refer to a single row from that table. That makes sense for a data structure in your program that contains a collection of rows. But I've come to the view that SQL tends to read better if the names of the database tables are singular, because in SQL you're writing assertions about individual rows, not the tables in their entirety. So I would write something like select T.name, T.id from Trail T but I would assign the resulting list of rows to a variable named "trails" in my program. -- Greg -- https://mail.python.org/mailman/listinfo/python-list