From alexkleider at gmail.com Sun Jun 2 22:44:35 2024 From: alexkleider at gmail.com (Alex Kleider) Date: Sun, 2 Jun 2024 19:44:35 -0700 Subject: [Tutor] use of dict() function Message-ID: #!/usr/bin/env python3 """ Question: I created a class which I initially coded as in Rec0. I then read[1] that calling dict(mapping) returns a new dict essentially providing the functionality of my class (except for the call-ability feature.) The interesting thing is that calling dict(mapping) within a class definition seems to result in different behavior than when called elsewhere. Is there an explanation??? The following code hopefully illustrates what I'm on about. Cheers, Alex Kleider [1]: https://www.thepythoncodingstack.com/p/python-dict-is-more-versatile-than-you-may-think """ class Rec0(dict): def __init__(self, rec): for key, value in rec.items(): self[key] = value def __call__(self, fstr): return fstr.format(**self) class Rec1(dict): def __init__(self, rec): self = dict(rec) def __call__(self, fstr): return fstr.format(**self) def test(): d0 = {"husband": "Alex", "wife": "June", "daughter": "Tanya", "son": "Kelly", } d1 = dict(d0) d1["grand_daughter"] = "Isabella" print("Using dict function directly...") print(" d1 should (and does) contain five entries as follows:") print(d1); print() d0 = {"husband": "Alex", "wife": "June", "daughter": "Tanya", "son": "Kelly", } d1 = Rec0(d0) d1["grand_daughter"] = "Isabella" print("Using Rec0 (which doesn't use the dict() function)...") print(" d1 also contain five entries as follows:") print(d1); print() d0 = {"husband": "Alex", "wife": "June", "daughter": "Tanya", "son": "Kelly", } d1 = Rec1(d0) d1["grand_daughter"] = "Isabella" print("Using Rec1 (which uses the dict() function)...") print(" d1 should (but doesn't) contain the five entries:") print(d1); print() if __name__ == "__main__": test() From PythonList at DancesWithMice.info Mon Jun 3 01:00:14 2024 From: PythonList at DancesWithMice.info (dn) Date: Mon, 3 Jun 2024 17:00:14 +1200 Subject: [Tutor] use of dict() function In-Reply-To: References: Message-ID: <07b50bc8-6fe3-431c-8878-be589a17b5db@DancesWithMice.info> On 3/06/24 14:44, Alex Kleider wrote: > #!/usr/bin/env python3 > """ > Question: > I created a class which I initially coded as in Rec0. > I then read[1] that calling dict(mapping) returns a new dict > essentially providing the functionality of my class (except > for the call-ability feature.) > The interesting thing is that calling dict(mapping) within a class > definition seems to result in different behavior than when called > elsewhere. > Is there an explanation??? Take a look at type( d1 ) when returned by Rec0 and compare with Rec1. The problem is not so much the dict() call, but the process of combining two dictionaries (the incoming rec, and the class's self.__dict__). Try self.update( dict( rec ) ) for all your dreams to come True. The realise that the dict() is unnecessary. Why was it there in the first place? -- Regards, =dn From Luc.Krasicky at cibc.com Thu Jun 6 18:01:27 2024 From: Luc.Krasicky at cibc.com (Krasicky, Luc) Date: Thu, 6 Jun 2024 22:01:27 +0000 Subject: [Tutor] PIP SSL Errno 11001 Message-ID: Hello, I'm currently working on an issue I'm having with PIP. I am on windows 10 running PY version 3.12 with pip version 23.2.1. I am on a corporate computer in my office. I cannot install packages. I run the command below and get the following error: >pip install pandas WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))': /simple/pandas/ WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))': /simple/pandas/ WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))': /simple/pandas/ WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))': /simple/pandas/ WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))': /simple/pandas/ ERROR: Could not find a version that satisfies the requirement pandas (from versions: none) ERROR: No matching distribution found for pandas I've done a couple of things to try and solve the issue, but still cannot. I tried running the below: pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org numpy I added a pip.ini file to the >AppData>Roaming>Pip that contains the following: [global] trusted-host = files.pythonhosted.org pypi.org pypi.python.org proxy = myproxy (left this out for obvious reasons) I also tried adding my user/password to the proxy. Am I screwing up the format of my proxy? Do I need to somehow include my IP address? I am not sure where to go from here. Please let me know if you have any ideas! ________________________________ This message, including any attachments, is intended only for the use of the individual(s) to which it is addressed and may contain information that is privileged/confidential. Any other distribution, copying or disclosure is strictly prohibited. If you are not the intended recipient or have received this message in error, please notify us immediately by reply email and permanently delete this message including any attachments, without reading it or making a copy. You are receiving this email because our records show that you have a relationship with one or more of the CIBC Capital Markets lines of business of Canadian Imperial Bank of Commerce (CIBC) or CIBC World Markets Inc., which includes Investment and Corporate Banking and Global Markets. If you believe you are receiving this message in error or you no longer wish to receive electronic messages from us, you may unsubscribe at any time. If you experience challenges with the unsubscribe link, reply to this email with the Subject Line "Unsubscribe" and Cc: Mailbox.CASLUnsubscribe at cibc.com. Please note that by selecting unsubscribe, we will only be able to send you emails that are required or permitted by law. Our mailing address is : CIBC CASL Unsubscribe, CIBC Head Office, 81 Bay St., CIBC Square, Toronto, Ontario Canada M5J 0E7 From mats at wichmann.us Sat Jun 8 10:56:39 2024 From: mats at wichmann.us (Mats Wichmann) Date: Sat, 8 Jun 2024 08:56:39 -0600 Subject: [Tutor] PIP SSL Errno 11001 In-Reply-To: References: Message-ID: On 6/6/24 16:01, Krasicky, Luc via Tutor wrote: > Hello, > > I'm currently working on an issue I'm having with PIP. I am on windows 10 running PY version 3.12 with pip version 23.2.1. I am on a corporate computer in my office. > > I cannot install packages. I run the command below and get the following error: > >> pip install pandas > WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))': /simple/pandas/ ... > ERROR: Could not find a version that satisfies the requirement pandas (from versions: none) > ERROR: No matching distribution found for pandas > > I've done a couple of things to try and solve the issue, but still cannot. I tried running the below: > pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org numpy > > I added a pip.ini file to the >AppData>Roaming>Pip that contains the following: > [global] > trusted-host = files.pythonhosted.org pypi.org pypi.python.org > proxy = myproxy (left this out for obvious reasons) > > > I also tried adding my user/password to the proxy. > > Am I screwing up the format of my proxy? Do I need to somehow include my IP address? > > I am not sure where to go from here. Please let me know if you have any ideas! You seem to be on the right track. I'd use, while debugging, PIP_CONFIG_FILE to make sure you're really getting your file picked up. proxy settings have to include a scheme, since you (understandably) obscured yours, we can't see if you're actually doing that. I used to have this problem early on at my next-to-last corporate setting, sometimes you just need some help if they're blocking things at IT. Fortunately, haven't had to deal with that scenario for many many years now so don't have anything further useful to add. I know the question comes up periodically, you're certainly not alone - maybe Stack Overflow has some suggestions? From __peter__ at web.de Wed Jun 12 04:03:54 2024 From: __peter__ at web.de (Peter Otten) Date: Wed, 12 Jun 2024 10:03:54 +0200 Subject: [Tutor] use of dict() function In-Reply-To: References: Message-ID: On 03/06/2024 04:44, Alex Kleider wrote: You may have figured it out in the mean time, but note that > class Rec1(dict): > def __init__(self, rec): > self = dict(rec) assigning to self has no effect (on the class). self is just a name that you can bind anything to: >>> class Stuff: def __init__(self): print(f"before: {self})" self = 42 print(f"after: {self}") SyntaxError: invalid syntax >>> class Stuff: def __init__(self): print(f"before: {self})") self = 42 print(f"after: {self}") >>> Stuff() before: <__main__.Stuff object at 0x02BDD5B0>) after: 42 <__main__.Stuff object at 0x02BDD5B0> So you are basically overwriting dict.__init__() with a no-op Rec1.__init__(). The easiest fix is to omit the initializer: >>> class R(dict): def __call__(self, fmt): return fmt.format_map(self) >>> r = R({"a": 1}, b=2) >>> r["c"] = 3 >>> r {'a': 1, 'b': 2, 'c': 3} >>> r("{a} + {b} = {c}") '1 + 2 = 3' From alan.gauld at yahoo.co.uk Wed Jun 12 13:19:45 2024 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 12 Jun 2024 18:19:45 +0100 Subject: [Tutor] Couldn't install numpy on Python 2.7 In-Reply-To: References: Message-ID: On 12/06/2024 12:30, marc nicole via Python-list wrote: > I am trying to install numpy library on Python 2.7.15 in PyCharm but the > error message I get is: > I think we need much more information about which version of Numpy you are trying to install and how. You are running an out of date version(ie not the latest) of an unsupported (since 2019) version of Python. The latest urllib3 doesn't support 2.7 so you presumably are trying to install an old version? Which and from where? And given the antiquity of the setup you should probably mention OS versions too. > ERROR: Could not find a version that satisfies the requirement numpy (from >> versions: none) >> ERROR: No matching distribution found for numpy This suggests version matching is critical and so we need all versions of everything you are trying to use. >> fail. You can upgrade to a newer version of Python to solve this. For more >> information, see >> https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings >> InsecurePlatformWarning, > Any clues? I'd say the clues are in the error messages. You need to find an old numpy that matches your very old Python. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From alexkleider at gmail.com Wed Jun 12 13:58:58 2024 From: alexkleider at gmail.com (Alex Kleider) Date: Wed, 12 Jun 2024 10:58:58 -0700 Subject: [Tutor] use of dict() function In-Reply-To: References: Message-ID: On the contrary, I have _not_ figured it out! My goal is to have a way of creating an object (a class instance,) in this case a dict, without there being any chance of the original dict (the parameter of the init call) being modified. (... and also to have the additional feature of being able to "call" the instance and get the dict formatted as specified by the string parameter.) Using the dict function provides the mechanism to do the first part without the need of a class. Must I assign to an intermediary identifier rather than to self itself? i.e. self.value = dict(mapping) and then access the mapping using "instance.value" rather than "instance" by itself? Thanks for your input. Alex On Wed, Jun 12, 2024 at 1:11?AM Peter Otten via Tutor wrote: > > On 03/06/2024 04:44, Alex Kleider wrote: > > You may have figured it out in the mean time, but note that > > > class Rec1(dict): > > def __init__(self, rec): > > self = dict(rec) > > assigning to self has no effect (on the class). self is just a name that > you can bind anything to: > > >>> class Stuff: > def __init__(self): > print(f"before: {self})" > self = 42 > print(f"after: {self}") > > SyntaxError: invalid syntax > >>> class Stuff: > def __init__(self): > print(f"before: {self})") > self = 42 > print(f"after: {self}") > > > >>> Stuff() > before: <__main__.Stuff object at 0x02BDD5B0>) > after: 42 > <__main__.Stuff object at 0x02BDD5B0> > > So you are basically overwriting dict.__init__() with a no-op > Rec1.__init__(). The easiest fix is to omit the initializer: > > >>> class R(dict): > def __call__(self, fmt): return fmt.format_map(self) > > > >>> r = R({"a": 1}, b=2) > >>> r["c"] = 3 > >>> r > {'a': 1, 'b': 2, 'c': 3} > >>> r("{a} + {b} = {c}") > '1 + 2 = 3' > > > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor -- alex at kleider.ca (he/him) (sent from my current gizmo) From mats at wichmann.us Wed Jun 12 14:41:04 2024 From: mats at wichmann.us (Mats Wichmann) Date: Wed, 12 Jun 2024 12:41:04 -0600 Subject: [Tutor] use of dict() function In-Reply-To: References: Message-ID: <634341c7-7864-4b3b-8bbe-05b6e8f65df8@wichmann.us> On 6/12/24 11:58, Alex Kleider wrote: > On the contrary, I have _not_ figured it out! > My goal is to have a way of creating an object (a class instance,) in > this case a dict, without there being any chance of the original dict > (the parameter of the init call) being modified. You need to get pretty involved to accomplish that. ChainMap is a cheap approximation, which presumably is believed to be "good enough" in many cases. === docs: A ChainMap groups multiple dicts or other mappings together to create a single, updateable view. If no maps are specified, a single empty dictionary is provided so that a new chain always has at least one mapping. ... Lookups search the underlying mappings successively until a key is found. In contrast, writes, updates, and deletions only operate on the first mapping. === So the second (and additional) dicts in the chain don't get modified by normal dictionary operations, as long as they're done on the view (chain). But the non-primary can still be modified directly. And indirectly as well. Some of this has actually been requested many times as an "immutable dict". Because the term has been used for other data types, it was once formally proposed as FrozenDict, though the proposal was not accepted. You can find various attempts at implementation on the internet (I've been here too, have a need for a backing dict to not get accidentally modified when using an "override" object). Actually there have been two PEPs - one for a native type, one for an implementation in the collections module. If you want to have your head spin a bit, it's these two: https://peps.python.org/pep-0416/ https://peps.python.org/pep-0603/ The thing you have to think about is if your "d0" contains values that are mutable objects (list, an inner dict, etc.), and you fetch one through "d1", now you have a handle to that object, and while you can't modify "d0" through "d1" itself, if you modify the object you fetched, then "d0" will still look updated. > (... and also to have the additional feature of being able to "call" > the instance and get the dict formatted as specified by the string > parameter.) Why would you use a call method? typically a str or repr magic method would provide this functionality, that's what they exist for. From PythonList at DancesWithMice.info Wed Jun 12 14:45:51 2024 From: PythonList at DancesWithMice.info (dn) Date: Thu, 13 Jun 2024 06:45:51 +1200 Subject: [Tutor] use of dict() function In-Reply-To: References: Message-ID: <458ebf4e-8741-4a57-ad84-acfb4ad008fc@DancesWithMice.info> On 13/06/24 05:58, Alex Kleider wrote: > On the contrary, I have _not_ figured it out! Sorry to hear. Did you continue by questioning earlier reply? Given the two responses, was the question well-expressed or has it changed since? Both addressed "Is there an explanation???". > My goal is to have a way of creating an object (a class instance,) in > this case a dict, without there being any chance of the original dict > (the parameter of the init call) being modified. The common issue experienced when moving to Python from another programming language is that identifiers are only pointing to memory. Thus: >>> a = { key: value for key, value in enumerate( "abcde" ) } >>> b = a >>> b {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e'} result in a and b pointing to the same dictionary. Any change made to one will 'appear' as a change to the other. >>> a[ 0 ] = 'z' >>> b {0: 'z', 1: 'b', 2: 'c', 3: 'd', 4: 'e'} Choices to make a distinct copy of the original dict: c = dict( a ) d = a.copy() import copy; e = copy.deepcopy( a ) For proof, use id( ... ) to verify if a, b, c, d, and e point to the same or separate 'memory addresses'... (many of the above techniques, including help() and id(), also stated in Stephen's article) > (... and also to have the additional feature of being able to "call" > the instance and get the dict formatted as specified by the string > parameter.) Please provide examples of the expected behavior/what would like to achieve... > Using the dict function provides the mechanism to do the first part > without the need of a class. > Must I assign to an intermediary identifier rather than to self itself? > i.e. self.value = dict(mapping) > and then access the mapping using "instance.value" rather than > "instance" by itself? What were the results when you tried the two solutions provided earlier? Do they illustrate answers to this question? The article did not discuss sub-classing dict - only using the dict() function as a constructor (IIRC). Sub-classing Python's types can easily (quickly?) cause this sort of head-scratching. From https://docs.python.org/3/library/collections.html#collections.UserDict UserDict objects The class, UserDict acts as a wrapper around dictionary objects. The need for this class has been partially supplanted by the ability to subclass directly from dict; however, this class can be easier to work with because the underlying dictionary is accessible as an attribute. - which would grant the instance.value option, if that's your preference. > Thanks for your input. > Alex > > > On Wed, Jun 12, 2024 at 1:11?AM Peter Otten via Tutor wrote: >> >> On 03/06/2024 04:44, Alex Kleider wrote: >> >> You may have figured it out in the mean time, but note that >> >>> class Rec1(dict): >>> def __init__(self, rec): >>> self = dict(rec) >> >> assigning to self has no effect (on the class). self is just a name that >> you can bind anything to: >> >> >>> class Stuff: >> def __init__(self): >> print(f"before: {self})" >> self = 42 >> print(f"after: {self}") >> >> SyntaxError: invalid syntax >> >>> class Stuff: >> def __init__(self): >> print(f"before: {self})") >> self = 42 >> print(f"after: {self}") >> >> >> >>> Stuff() >> before: <__main__.Stuff object at 0x02BDD5B0>) >> after: 42 >> <__main__.Stuff object at 0x02BDD5B0> >> >> So you are basically overwriting dict.__init__() with a no-op >> Rec1.__init__(). The easiest fix is to omit the initializer: >> >> >>> class R(dict): >> def __call__(self, fmt): return fmt.format_map(self) >> >> >> >>> r = R({"a": 1}, b=2) >> >>> r["c"] = 3 >> >>> r >> {'a': 1, 'b': 2, 'c': 3} >> >>> r("{a} + {b} = {c}") >> '1 + 2 = 3' >> >> >> _______________________________________________ >> Tutor maillist - Tutor at python.org >> To unsubscribe or change subscription options: >> https://mail.python.org/mailman/listinfo/tutor > > > > -- > alex at kleider.ca (he/him) > (sent from my current gizmo) > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor -- Regards, =dn From mats at wichmann.us Wed Jun 12 14:47:37 2024 From: mats at wichmann.us (Mats Wichmann) Date: Wed, 12 Jun 2024 12:47:37 -0600 Subject: [Tutor] Couldn't install numpy on Python 2.7 In-Reply-To: References: Message-ID: <347246db-1ec4-423e-8482-31feb86a29a3@wichmann.us> On 6/12/24 11:19, Alan Gauld via Tutor wrote: >> ERROR: Could not find a version that satisfies the requirement numpy (from >>> versions: none) >>> ERROR: No matching distribution found for numpy > > This suggests version matching is critical and so we need > all versions of everything you are trying to use. the last version of numpy to support Python 2 was 1.15 The policy decision on that was here: https://numpy.org/neps/nep-0014-dropping-python2.7-proposal.html that does include a claim that pip installs ought to continue working: > To minimize disruption, running pip install numpy on Python 2 will continue to give the last working release in perpetuity, So as Alan says - more detailed information is needed. Did some other package in your chain indicate a newer numpy version and thus there's no way to resolve the version matrix? From __peter__ at web.de Wed Jun 12 14:59:57 2024 From: __peter__ at web.de (Peter Otten) Date: Wed, 12 Jun 2024 20:59:57 +0200 Subject: [Tutor] use of dict() function In-Reply-To: References: Message-ID: <99dab666-575f-4e48-85c3-a9ec0bca87d1@web.de> On 12/06/2024 19:58, Alex Kleider wrote: > On the contrary, I have _not_ figured it out! > My goal is to have a way of creating an object (a class instance,) in > this case a dict, without there being any chance of the original dict > (the parameter of the init call) being modified. > (... and also to have the additional feature of being able to "call" > the instance and get the dict formatted as specified by the string > parameter.) > Using the dict function provides the mechanism to do the first part > without the need of a class. Subclassing dict like this class R(dict): def __call__(self, fmt): return fmt.format_map(self) should do that. As R inherits from dict and does not override the __init__() or __new__() method r = R(some_dict) copies some_dict's contents just like d = dict(some_dict) does, and provides the required formatting feature. > Must I assign to an intermediary identifier rather than to self itself? > i.e. self.value = dict(mapping) > and then access the mapping using "instance.value" rather than > "instance" by itself? Again: assigning to self has no effect. Inside the __init__() method the R, say, instance is already created and is basically a shallow copy of the original some_dict. At that point you only mutate r, and if you add, remove, or replace a key some_dict will not magically change. From mk1853387 at gmail.com Wed Jun 12 07:30:18 2024 From: mk1853387 at gmail.com (marc nicole) Date: Wed, 12 Jun 2024 13:30:18 +0200 Subject: [Tutor] Couldn't install numpy on Python 2.7 Message-ID: I am trying to install numpy library on Python 2.7.15 in PyCharm but the error message I get is: ERROR: Could not find a version that satisfies the requirement numpy (from > versions: none) > ERROR: No matching distribution found for numpy > c:\python27\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py:164: > InsecurePlatformWarning: A true SSLContext object is not available. This > prevents urllib3 fro > m configuring SSL appropriately and may cause certain SSL connections to > fail. You can upgrade to a newer version of Python to solve this. For more > information, see > https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings > InsecurePlatformWarning, Any clues? From nathan-tech at hotmail.com Thu Jun 13 03:59:23 2024 From: nathan-tech at hotmail.com (Nathan Smith) Date: Thu, 13 Jun 2024 08:59:23 +0100 Subject: [Tutor] recommends for online envionments for running pygame and python programs Message-ID: Hello list, I was wondering if anyone has recommends for online environments for running pygame. There's a few knocking around, but they are all restricted in some way. Looking at the pygame examples folder in GitHub, they draw from bmp files and .wav files to run their games (such as the little alien arcade). None of the pygame online runners I have found would let you run these.. Any suggestions? Nathan From mk1853387 at gmail.com Sat Jun 22 08:41:47 2024 From: mk1853387 at gmail.com (marc nicole) Date: Sat, 22 Jun 2024 14:41:47 +0200 Subject: [Tutor] How to go about a simple object grabbing in python (given coordinates of arms and objects) Message-ID: Hello to all of this magnificent community! I have this problem I had already spent a few days on and still can't figure out a proper solution. So, given the x,y,z coordinates of a target object and the offset x,y,z of arms of a robot, what is a good algorithm to perform to grab the object between the hands (either from both sides or from below all using both hands). Specifically, my problem is applied to a NAO robot environment where I retrieve a target object coordinates using the following code: tracker_service= session.service("ALTracker") xyz_pos = tracker_service.getTargetPosition(motion.FRAME_TORSO) src: http://doc.aldebaran.com/2-8/naoqi/motion/control-cartesian.html#motion-cartesian-effectors Then I get to move the right arm towards nearby the object using the following code: effector = "RArm" frame = motion.FRAME_TORSO effector_offset = almath.Transform(self.motion.getTransform(effector, frame, False)) effector_init_3d_position = almath.position3DFromTransform( effector_offset) target_3d_position = almath.Position3D(target_position) move_3d = target_3d_position - effector_init_3d_position moveTransform = almath.Transform.fromPosition(move_3d.x, move_3d.y, move_3d.z) target_transformer_list = list(moveTransform.toVector()) times = [2.0] axis_mask_list = motion.AXIS_MASK_VEL self.motion.transformInterpolations(effector, frame, target_transformer_list, axis_mask_list, times). src: http://doc.aldebaran.com/1-14/dev/python/examples/almath/index.html?highlight=offset This question is specific to NAO environment but in general how to go about this task? what is a most common algorithm used in this case? Do I have to also get the side of the object in order to know where exactly the arms should be placed? From threesomequarks at proton.me Sat Jun 22 17:04:05 2024 From: threesomequarks at proton.me (ThreeBlindQuarks) Date: Sat, 22 Jun 2024 21:04:05 +0000 Subject: [Tutor] How to go about a simple object grabbing in python (given coordinates of arms and objects) In-Reply-To: References: Message-ID: Marc, Could you specify what is wrong with what you are doing? you show us code that uses an environment you point to that is largely outside of basic Python. There is no one way to get from point A to point B and various constraints you have not mentioned can apply. How many joints does the assemblage have and what are the limits and costs associated with each. Cam there be barriers along a route, including to the side where they may brush part of your equipment. Are other things moving (independently even) that may end up blocking. You seem to need both "hands" and presumably at the same time. So solutions can take that into account. You need to define what is meant by contacting the object to move and you don't want to approach it and hit with some speed. So, the problem may be in parts. Get the hands rapidly enough in the vicinity and then do some fine coordinated motions to capture the object and then presumably move it. If you could point to what code is not doing what is expected, someone who knows the details or is willing to learn, might help, If you want an overall algorithm, there may be some people could share but they may not easily translate into the package of sorts you are using. But the web site you point us to may well already contain examples of doing some aspects that you might learn from. For me, this is too detailed to focus on as I struggle to figure out how to move my hands to different parts of my keyboard while looking ... And that may be one variant of an algorithm where instead of trying to move all the way, you move art-way and LOOK where you are, then repeat. Sent with Proton Mail secure email. On Saturday, June 22nd, 2024 at 8:41 AM, marc nicole wrote: > Hello to all of this magnificent community! > > I have this problem I had already spent a few days on and still can't > figure out a proper solution. > > So, given the x,y,z coordinates of a target object and the offset x,y,z of > arms of a robot, what is a good algorithm to perform to grab the object > between the hands (either from both sides or from below all using both > hands). > > Specifically, my problem is applied to a NAO robot environment where I > retrieve a target object coordinates using the following code: > > tracker_service= session.service("ALTracker") > xyz_pos = tracker_service.getTargetPosition(motion.FRAME_TORSO) > > > src: > http://doc.aldebaran.com/2-8/naoqi/motion/control-cartesian.html#motion-cartesian-effectors > > > Then I get to move the right arm towards nearby the object using the > following code: > > effector = "RArm" > > frame = motion.FRAME_TORSO > effector_offset = > almath.Transform(self.motion.getTransform(effector, frame, False)) > effector_init_3d_position = almath.position3DFromTransform( > effector_offset) > > target_3d_position = almath.Position3D(target_position) > move_3d = target_3d_position - effector_init_3d_position > moveTransform = almath.Transform.fromPosition(move_3d.x, > move_3d.y, move_3d.z) > target_transformer_list = list(moveTransform.toVector()) > times = [2.0] > axis_mask_list = motion.AXIS_MASK_VEL > self.motion.transformInterpolations(effector, frame, > target_transformer_list, axis_mask_list, times). > > src: http://doc.aldebaran.com/1-14/dev/python/examples/almath/index.html?highlight=offset > This question is specific to NAO environment but in general how to go > about this task? what is a most common algorithm used in this case? Do > I have to also get the side of the object in order to know where > exactly the arms should be placed? > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor From alan.gauld at yahoo.co.uk Sun Jun 23 04:27:04 2024 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sun, 23 Jun 2024 09:27:04 +0100 Subject: [Tutor] How to go about a simple object grabbing in python (given coordinates of arms and objects) In-Reply-To: References: Message-ID: On 22/06/2024 13:41, marc nicole wrote: > So, given the x,y,z coordinates of a target object and the offset x,y,z of > arms of a robot, what is a good algorithm to perform to grab the object > between the hands (either from both sides or from below all using both > hands). > > Specifically, my problem is applied to a NAO robot environment where I > retrieve a target object coordinates using the following code: This is almost entirely outside the Python domain and all within your 3rd party environment. Do they have a user forum or mailing list? You will probably get better results asking there? Another possibility is that you are using a Python wrapper around a C (or other language) library and there might be FAQs, fora or lists supporting that. If so you should be able to translate their examples to your Python code? In terms of generic solutions the only thing I can suggest that might help is to research collision detection algorithms. Wikipedia is likely a good starting point. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From mk1853387 at gmail.com Sat Jun 22 17:54:21 2024 From: mk1853387 at gmail.com (marc nicole) Date: Sat, 22 Jun 2024 23:54:21 +0200 Subject: [Tutor] How to go about a simple object grabbing in python (given coordinates of arms and objects) In-Reply-To: References: Message-ID: My code is just an attempt at the task, it is not exact as what relates to the coordinates (e.g., doesn't account for the size of the object. I would like to have a idea on the general approach to such problems (even a pseudo code would do) "Get the hands rapidly enough in the vicinity and then do some fine coordinated motions to capture the object and then presumably move it." seems to be a good approach indeed, The grabbing with both hands code should be more precise. Thanks for the help anyways! Le sam. 22 juin 2024 ? 23:04, ThreeBlindQuarks a ?crit : > Marc, > > Could you specify what is wrong with what you are doing? you show us code > that uses an environment you point to that is largely outside of basic > Python. > > There is no one way to get from point A to point B and various constraints > you have not mentioned can apply. How many joints does the assemblage have > and what are the limits and costs associated with each. Cam there be > barriers along a route, including to the side where they may brush part of > your equipment. Are other things moving (independently even) that may end > up blocking. > > You seem to need both "hands" and presumably at the same time. So > solutions can take that into account. You need to define what is meant by > contacting the object to move and you don't want to approach it and hit > with some speed. > > So, the problem may be in parts. Get the hands rapidly enough in the > vicinity and then do some fine coordinated motions to capture the object > and then presumably move it. > > If you could point to what code is not doing what is expected, someone who > knows the details or is willing to learn, might help, If you want an > overall algorithm, there may be some people could share but they may not > easily translate into the package of sorts you are using. > > But the web site you point us to may well already contain examples of > doing some aspects that you might learn from. > > For me, this is too detailed to focus on as I struggle to figure out how > to move my hands to different parts of my keyboard while looking ... > > And that may be one variant of an algorithm where instead of trying to > move all the way, you move art-way and LOOK where you are, then repeat. > > > Sent with Proton Mail secure email. > > On Saturday, June 22nd, 2024 at 8:41 AM, marc nicole > wrote: > > > Hello to all of this magnificent community! > > > > I have this problem I had already spent a few days on and still can't > > figure out a proper solution. > > > > So, given the x,y,z coordinates of a target object and the offset x,y,z > of > > arms of a robot, what is a good algorithm to perform to grab the object > > between the hands (either from both sides or from below all using both > > hands). > > > > Specifically, my problem is applied to a NAO robot environment where I > > retrieve a target object coordinates using the following code: > > > > tracker_service= session.service("ALTracker") > > xyz_pos = tracker_service.getTargetPosition(motion.FRAME_TORSO) > > > > > > src: > > > http://doc.aldebaran.com/2-8/naoqi/motion/control-cartesian.html#motion-cartesian-effectors > > > > > > Then I get to move the right arm towards nearby the object using the > > following code: > > > > effector = "RArm" > > > > frame = motion.FRAME_TORSO > > effector_offset = > > almath.Transform(self.motion.getTransform(effector, frame, False)) > > effector_init_3d_position = almath.position3DFromTransform( > > effector_offset) > > > > target_3d_position = almath.Position3D(target_position) > > move_3d = target_3d_position - effector_init_3d_position > > moveTransform = almath.Transform.fromPosition(move_3d.x, > > move_3d.y, move_3d.z) > > target_transformer_list = list(moveTransform.toVector()) > > times = [2.0] > > axis_mask_list = motion.AXIS_MASK_VEL > > self.motion.transformInterpolations(effector, frame, > > target_transformer_list, axis_mask_list, times). > > > > src: > http://doc.aldebaran.com/1-14/dev/python/examples/almath/index.html?highlight=offset > > This question is specific to NAO environment but in general how to go > > about this task? what is a most common algorithm used in this case? Do > > I have to also get the side of the object in order to know where > > exactly the arms should be placed? > > _______________________________________________ > > Tutor maillist - Tutor at python.org > > To unsubscribe or change subscription options: > > https://mail.python.org/mailman/listinfo/tutor > From mk1853387 at gmail.com Mon Jun 24 05:23:30 2024 From: mk1853387 at gmail.com (marc nicole) Date: Mon, 24 Jun 2024 11:23:30 +0200 Subject: [Tutor] How to go about a simple object grabbing in python (given coordinates of arms and objects) In-Reply-To: References: Message-ID: What are the parameters to account for in this type of algorithm? are there some checks to perform the arm moves ? for example angle moves or cartesian moves based on some distance thresholds? Any idea about the pseudo-algorithm is welcome. Thanks. Le dim. 23 juin 2024 ? 10:33, Alan Gauld via Tutor a ?crit : > On 22/06/2024 13:41, marc nicole wrote: > > > So, given the x,y,z coordinates of a target object and the offset x,y,z > of > > arms of a robot, what is a good algorithm to perform to grab the object > > between the hands (either from both sides or from below all using both > > hands). > > > > Specifically, my problem is applied to a NAO robot environment where I > > retrieve a target object coordinates using the following code: > > This is almost entirely outside the Python domain and all within > your 3rd party environment. Do they have a user forum or mailing > list? You will probably get better results asking there? > > Another possibility is that you are using a Python wrapper around > a C (or other language) library and there might be FAQs, fora or > lists supporting that. If so you should be able to translate > their examples to your Python code? > > In terms of generic solutions the only thing I can suggest that > might help is to research collision detection algorithms. > Wikipedia is likely a good starting point. > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > From avi.e.gross at gmail.com Mon Jun 24 17:57:00 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Mon, 24 Jun 2024 17:57:00 -0400 Subject: [Tutor] How to go about a simple object grabbing in python (given coordinates of arms and objects) In-Reply-To: References: Message-ID: <000601dac681$70bbaf00$52330d00$@gmail.com> Marc, Several people have supplied feedback on whether your request is a good fit for here. Ultimately it is up to the owner/moderator. In particular, your request to the Tutor List may not fit the purpose and be a bit complex and to the main Python List also outside some common usage whether it is about a specific module or product you are using, or asking about algorithms in a very general way. You question has evolved to being about algorithms, more than about Python as a basic language or even commonly used modules. So, I suggest you simplify your model and then maybe bring it in-line with the module(s) you showed us you were using. Some of what you ask sounds like it would be extremely commonly done in things like robotics, or even just machines with moving parts. Consider the somewhat related concept often seen of how you get from one place to another in parts of Manhattan where most of the streets run either in one direction or the orthogonal direction. How do you get from say East 14th Street at 1st Avenue to West 28th Street and 11th Avenue? This is a slight imitation of how to move a robotic arm that can mainly either go one way or another but not both at once. And, in the real world, parts of Manhattan are more complex with streets ending or renaming or running more diagonally or huge voids like Central Park. The number of solutions is huge for walking, and smaller for driving as some streets are one way. But assuming you avoid wasteful paths (except when roads are closed for endless purposes) and you do not take a path through Brooklyn, Queens and The Bronx and back to Manhattan as in the NY Marathon that also touches another borough, the solutions mainly look like this: Go as far horizontally as you need and then as far vertically. Or, do vertical, then horizontal. Or lots of combined versions such as climbing stairs by doing a block or three one way then some in the other and repeat. The above is referred to as Manhattan Distance, as compared to other measures like Euclidean distance. So back to your robot arm, you can see a set of simple solutions where you make a sort of triangle with the direct Euclidean arm being a hypoteneuse and the X and Y movements are the other two sides. You can then break up your problem as heading one way and pausing and turning the other way and stopping just short of the object you want. If there are no obstacles, you can do that in either order. Or, you could alternate in smaller amounts and get to the same destination. Grabbing it would be something else I will not address except to say that depending on what is grabbing and how it is shaped, you may need to aim not for the object, but the appropriate distance and direction so that when you stop moving, the "grasper" can close on it, again, avoiding existing obstacles. And note, speed is a consideration as many things need to be approached slowly and gently. Next, consider what it would mean if you could have a combined motion based on both operations allowed at the same time. Consider a robot that is on wheels that can move horizontally while also having a "lift" component that lifts the part with the graspers vertically. Both could be programmed to run in tandem at appropriate speeds so the graspers are traveling along the hypotenuse I mention and are going the shortest path. This might be faster and more economical in other ways but can be more complex. And, it may be the robot does not have power or computing ability to do both at the same time. Your design is beyond vague. Both of the approaches above make a plan and carry it out. But in the real world, many algorithms must adjust and work somewhat probabilistically. One algorithm for say catching a moving object, especially one that can change speed and direction a bit, like a running dog or a kite flying in the wind, is to locate where the object seems to be now, perhaps just a direction and a guess at distance, and maybe with some observation make a guess at where it might be at some time in the future that is approximately when you might move the robot near there. Then, use a technique like above (or completely different) that perhaps aims to get you something like halfway there. Monitor along the way to update your position and the newest destination position (if it is moving) and re-evaluate and adjust for the next round and maybe evaluate again as you approach halfway or so, again. Eventually, if you are close, slow down and gradually try to come to a stop where you can grab. If the object reacts to your attempting to go after it, it can be complex. And, you may overshoot and sort of circle back. Now, expand the problem more if needed. What does the robot look like. How many places can it bend? For example, can it have something like two or more elbows, perhaps one allowing twisting of up to 30 degrees and one moving forward and backward and another allowing movement side to side, up to some number of degrees. Are all these degrees of freedom absolute or are there constraints? For example, to turn beyond some number of combined degrees may not be allowed, and instead of turning 400 degrees clockwise, you simply move forward or back to a 40 degree angle from some baseline. Perhaps bending certain ways while carrying some kind of weight, can cause it to topple. There can be an amazing number of considerations that cannot be anticipated and depend on specific choices in making a robot. A longer arm, for example, requires fewer degrees of turn to move some known amount. As before, there are an amazing number of ways to do such things in any language as we are discussing "algorithms." If the goal is finding A WAY, any simpler ones will do. If it is to find an optimum way, we have tons you need to learn and consider. If this was a contest and a contestant on the other side of the object was supposed to start at the same time as you, and the first to grab the object wins, ... And, if this has machine learning components, which python is in some ways well suited to, you may design a robot that moves clumsily and almost randomly, at first, and then "learns" from such experiments and gradually figures out better and maybe even better ways until it just does well at reaching and grasping for any similar enough problems and maybe even somewhat different ones. I suspect that is more than you need but in real-world robotics, may be part of how to make more sophisticated and even general-purpose robots. But if you want to talk more about python in doing parts of this, there are several things to consider. Base python has data structures you can use to store and manipulate many things you may need to keep track of, or if planning a whole routine in advance, things like lists to hold the steps you can then hand over to function. Add-on modules like numpy can be very helpful in extending python for some purposes, as an example. There are probably many functions that already do things like given two points, calculate the slope and distance of a direct line between them, or compare two or more approaches and return what is best in some way and so on. There ways of running things in parallel while sharing some data while making sure to avoid them interfering with each other. You can set timers to wake up and recalculate and much more. Then there are all kinds of modules that help you with parts. There is a good chance that whatever you showed us is just one of many such modules people have shared or sold for purposes similar enough to your robot problem. But if your main goal is to do this mainly with the kind of functionality you pointed at, since likely none of us have read the documentation, nor care to without getting paid a lot, it means you should be reading a lot and looking carefully at examples that may apply AND finding resources more about that than asking people about "python" and especially asking python people how one does things in robotics. Mose specific questions such as how to calculate a distance using python, will likely get helpful responses, and brief but complete examples of code that you want debugged, may also be responded to. But asking for complex algorithms in the abstract probably will result in silence or ever more elaborate debates till a moderator suggest a halt! LOL! Python, like many languages, is a fairly general purpose language that can do many things well, and some less well, and some mainly by standing on it's head while including software built in other languages. Your project may happen to be in python, but more likely most of it should be using functions built-in to whatever add-ons you are using if it is designed to do what you want. Your goal is not to create it all from scratch, I would think. You may end up using just a little base python to glue things together. Good Luck. -----Original Message----- From: Python-list On Behalf Of marc nicole via Python-list Sent: Monday, June 24, 2024 5:24 AM To: Alan Gauld ; python-list at python.org; Tutor at python.org Subject: Re: [Tutor] How to go about a simple object grabbing in python (given coordinates of arms and objects) What are the parameters to account for in this type of algorithm? are there some checks to perform the arm moves ? for example angle moves or cartesian moves based on some distance thresholds? Any idea about the pseudo-algorithm is welcome. Thanks. Le dim. 23 juin 2024 ? 10:33, Alan Gauld via Tutor a ?crit : > On 22/06/2024 13:41, marc nicole wrote: > > > So, given the x,y,z coordinates of a target object and the offset x,y,z > of > > arms of a robot, what is a good algorithm to perform to grab the object > > between the hands (either from both sides or from below all using both > > hands). > > > > Specifically, my problem is applied to a NAO robot environment where I > > retrieve a target object coordinates using the following code: > > This is almost entirely outside the Python domain and all within > your 3rd party environment. Do they have a user forum or mailing > list? You will probably get better results asking there? > > Another possibility is that you are using a Python wrapper around > a C (or other language) library and there might be FAQs, fora or > lists supporting that. If so you should be able to translate > their examples to your Python code? > > In terms of generic solutions the only thing I can suggest that > might help is to research collision detection algorithms. > Wikipedia is likely a good starting point. > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > -- https://mail.python.org/mailman/listinfo/python-list From mk1853387 at gmail.com Wed Jun 26 11:29:00 2024 From: mk1853387 at gmail.com (marc nicole) Date: Wed, 26 Jun 2024 17:29:00 +0200 Subject: [Tutor] How to install tensorflow on Python 2.7 in Windows? Message-ID: Browsing the available version of tensorflow for the dates before January 2021 (date when Python 2.7 stopped being supported) I can't find a tensorflow version for Python 2.7 that works under Windows. The reference site I use is https://pypi.org/project/tensorflow/ Anybody can point out a compatible .whl file with Python 2.7 and Windows? From mats at wichmann.us Wed Jun 26 15:40:12 2024 From: mats at wichmann.us (Mats Wichmann) Date: Wed, 26 Jun 2024 13:40:12 -0600 Subject: [Tutor] How to install tensorflow on Python 2.7 in Windows? In-Reply-To: References: Message-ID: On 6/26/24 09:29, marc nicole wrote: > Browsing the available version of tensorflow for the dates before January > 2021 (date when Python 2.7 stopped being supported) I can't find a > tensorflow version for Python 2.7 that works under Windows. > > The reference site I use is https://pypi.org/project/tensorflow/ > > Anybody can point out a compatible .whl file with Python 2.7 and Windows? The last version of tensorflow to support Python 2.7 was indeed 2.1, and I don't think there was *ever* an official Windows wheel for Python 2, but I'm not that expert to be completely sure. tensorflow support on Windows has never been good, and in a way they've given up, at least part of the fight: they no longer produce official releases for Windows with GPU support (although you may be able to get one from the vendor that produces the GPU hardware like Nvidia or Intel, or from a third party like Amazon Web Services). The official recommendation for WIndows used to be "build your own" (which nearly always failed), then for a few years they tried making Windows builds, now the new "best practice" recommendation is to install on WSL if you want to run on a Windows box (this *might* work for you, unless you're also on an ancient Windows that won't run WSL). Or, try seeing if you can find a docker setup (which, again, will give you a Linux environment running tensorflow). Note that like your other problem, getting numpy going, this is going to be an uphill battle trying to cobble things together to run on 2.7. This is really the problem when something like Python goes out of date / out of support: it's not that it magically stops working, it's that vast amounts of the ecosystem around it stop providing support for *their* bits on the old version, and the combinations become progressively harder to make work.