Re: Application Preferences

2019-08-20 Thread Barry Scott



> On 19 Aug 2019, at 20:37, Dennis Lee Bieber  wrote:
> 
> On Mon, 19 Aug 2019 18:01:17 +, dboland9 via Python-list
>  declaimed the following:
> 
>> Wow, what happened here?  I posted this to the Python discussion group as it 
>> is a Python question, not an SQL question.  That said, I agree with what you 
>> have said, and that was the plan.  Plans get changed.  A number of apps. 
>> allow the user to specify the location of data and configuration files, and 
>> for good reason.  Some folders are auto-backup in that they are either 
>> journaled or backed up multiple times per day.  I think that is the argument 
>> in this case.
>> 
>   The trick with allowing a user to specify said location is that, unless
> you use some standard location to store the redirection, the user has to
> always provide the location when launching the application. And if you are
> using a standard location for the redirection, you might as well use that
> for the configuration data (since redirected user data location can be
> stored in the config file).

I understood your requirements. User picks the folder to store app files into.
The app then needs to store that folder somewhere.

I would ask the user for the their preferred location and store that folder in 
a OS standard location.

I do exactly that with Scm-Workbench. The user picks the folder to check out 
repos into
and I store that choice in the standard location.

Barry

-- 
https://mail.python.org/mailman/listinfo/python-list


python requests get from API and post to another API and remote u'

2019-08-20 Thread Noah

Hi,

I am trying to migrate information and data between two systems using 
their corresponding APIs. I am using python requests.


I place a get request and the response from the API is "{'id': 32, 
'description': u'Firewall Outside', 'address': u'10.10.10.230/30'}"


I then take that information and attempt post it to the other API.  The 
data is not accepted and the result is an HTTP 400 code.


I tried posting with postman and still rejected.

I can post to the second API if I change the data to look like this: 
{"id": 32, "description": "Firewall Outside", "address": "10.10.10.230/30"}


How can I remove all u' from the get data or from the data I am 
attempting to post?


Cheers\
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to login remote windos device using python

2019-08-20 Thread Iranna Mathapati
Hi Kyle,

I have tried with as per above attached links and it leads following error:
NOTE: Its able to connect  local

Failed to connect remote windows
>>> import wmi
>>> c = wmi.WMI("XX.XX.XX.XX", user=r"XXX\XXX", password="")
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python27\lib\site-packages\wmi.py", line 1290, in connect
handle_com_error ()
  File "C:\Python27\lib\site-packages\wmi.py", line 241, in handle_com_error
raise klass (com_error=err)
wmi.x_wmi: 

On Tue, Aug 20, 2019 at 7:03 AM Kyle Stanley  wrote:

> I would recommend checking out WMI: https://pypi.org/project/WMI/
>
> For remote connection as a named user (official WMI docs):
> http://timgolden.me.uk/python/wmi/tutorial.html#connecting-to-a-remote-machine-as-a-named-user
>
> Also, another example (unofficial):
> https://stackoverflow.com/questions/18961213/how-to-connect-to-a-remote-windows-machine-to-execute-commands-using-python.
> This was done in Python2, but the example is still useful.
>
> On Mon, Aug 19, 2019 at 2:11 PM Iranna Mathapati 
> wrote:
>
>> Hi Team,
>>
>> can you please let me know, How to login the remote Windows machine using
>> python??
>>
>> Thanks
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python requests get from API and post to another API and remote u'

2019-08-20 Thread Chris Angelico
On Tue, Aug 20, 2019 at 6:59 PM Noah  wrote:
>
> Hi,
>
> I am trying to migrate information and data between two systems using
> their corresponding APIs. I am using python requests.
>
> I place a get request and the response from the API is "{'id': 32,
> 'description': u'Firewall Outside', 'address': u'10.10.10.230/30'}"
>
> I then take that information and attempt post it to the other API.  The
> data is not accepted and the result is an HTTP 400 code.
>
> I tried posting with postman and still rejected.
>
> I can post to the second API if I change the data to look like this:
> {"id": 32, "description": "Firewall Outside", "address": "10.10.10.230/30"}
>
> How can I remove all u' from the get data or from the data I am
> attempting to post?
>

Use Python 3. Your problems with Unicode will either disappear, or
become a lot clearer.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: absolute path to a file

2019-08-20 Thread Cameron Simpson

Please remember to CC the list.

On 19Aug2019 22:06, Paul St George  wrote:

On 19/08/2019 14:16, Cameron Simpson wrote:

[...]
There's a remark on that web page I mentioned that suggests that the 
leading '//' indicates the filename is relative to the Blender model, 
so the context directory for the '//' is likely 
/Users/Lion/Desktop/test8.


Yes. That makes sense. The reason I was testing with two images, one 
at /Users/Lion/Desktop/test8/image01.tif and the other at 
/Users/Lion/Desktop/images/image02.tif is that I cannot rely on images 
being in the same folder as the Blender file.


So, let's assume the context directory is /Users/Lion/Desktop/test8
and see how we get on below.

[...]
realpath needs a UNIX path. Your //image01.tif isn't a UNIX path, it 
is a special Blender path. First you need to convert it. By replacing 
'//' with the blend file's directory. Then you can call realpath. If 
you still need to.


Understood. Now. Thanks!


[...snip...]


Did you just [...snip...] yourself?


Yes. It keeps the surrounding context manageable. In this way you know 
to which text I am referring, without having to wade through paragraphs 
to guess what may be relevant.



   from os.path import dirname

   # Get this from somewhere just hardwiring it for the example.
   # Maybe from your 'n' object below?
   blend_file = '/Users/Lion/Desktop/test8/tifftest8.blend'

Is this setting a relative path?


   blender_image_file = n.image.filename

   unix_image_file = unblenderise(blender_image_file, dirname(blend_file))

Now you have a UNIX path. If blend_file is an absolute path, 
unix_image_path will also be an absolute path. But if blend_file is 
a relative path (eg you opened up "tifftest8.blend") unix_image_path 
will be a relative path.


Does unix_image_path = unix_image_file?


Yeah, sorry,  my mistake.


Two possibilities here.
blend_file (and so unix_image_file) is an absolute path OR blend_file 
(and so unix_image_file) is a relative path.


I just want to check my understanding. If I supply the path to 
blend_file then it is absolute, and if I ask Python to generate the 
path to blend_file from within Blender it is relative. Have I got it?


Not quite. What seems to be the situation is:

You've got some object from Blender called "n.image", which has a 
".file" attribute which is a Blender reference to the image file of the 
form "//image01.tif".


I presume that Blender has enough state inside "n" or "n.image" to 
locate this in the real filesystem; maybe it has some link to the 
Blender model of your blend file, and thus knows the path to the blend 
file and since //image01.tif is a reference relative to the blend file, 
it can construct the UNIX path to the file.


You want to know the UNIX pathname to the image file (maybe you want to 
pass it to some unrelated application to view the file or something).


So you need to do what Blender would do if it needs a UNIX path (eg to 
open the file).


The formula for that is dirname(path_to_blendfile) with n.image.file[2:] 
appended to it. So that's what we do with unblenderise(): if the 
filename is a "Blender relative name", rip off the "//" and prepend the 
blend file directory path. That gets you a UNIX path which you can hand 
to any function expecting a normal operating system pathname.


Whether that is an absolute path or a relative path is entirely "does 
the resulting path start with a '/'"?


An absolute path starts with a slash and is relative to the root of the 
filesystem. You can use such a path regardless of what your current 
working directory is, because it doesn't use the working directory.


A relative path doesn't start with a slash and is relative to the 
current working directory. It only works if you're in the right working 
directory.


_Because_ a relative path depends on the _your_ working directory, 
usually we pass around absolute paths if we need to tell something else 
about a file, because that will work regardless if what _their_ working 
directory may be.


So, you may well want to turn a relative path into an absolute path...

If I decided not to supply the path and so ended up with a relative 
UNIX path, I could now use realpath or abspath to find the absolute 
path. Have I still got it?


This is correct.

Abspath may even call realpath to do its work, unsure.

It works very well. So thank you! I tested it with a Blend file that 
had two images, one in the same folder as the Blend file and the other 
was in a folder on the Desktop called 'images'.


The initial results were:
Plane uses image01.tif saved at //image01.tif which is at 
/Users/Lion/Desktop/test8/image01.tif
Plane uses image02.tif saved at //../images/image02.tif which is at 
/Users/Lion/Desktop/test8/../images/image02.tif
BUT as you say, this was easily sorted by using os.path.realpath or 
os.path.abspath. Both worked equally well.


Yep. Abspath does some things in a purely lexical way: it resolves '.' 
and '..' components in the path even if they don'

Re: Which editor is suited for view a python package's source?

2019-08-20 Thread Bev In TX
Search for “Choose” (without the quote marks) on the following webpage to see 
the differences between the community and commercial versions:
https://www.jetbrains.com/pycharm/features/

From the following webpage, “Microsoft Windows 7 SP1 or later”
https://www.jetbrains.com/help/pycharm/installation-guide.html?_ga=2.186403823.798151923.1566294266-889030968.1566294266

Bev

> On Aug 19, 2019, at 9:24 PM, [email protected] wrote:
> 
> Nick Sarbicki於 2019年8月19日星期一 UTC+8下午5時33分27秒寫道:
>> PyCharm takes you to the source code within the editor for any
>> variables/functions/classes/modules if you ctrl+click on what you want to
>> see. It allows you to browse the relevant bits of code quickly, as well as
>> let you change them in your local environment if need be.
>> 
>> That way you don't have to download the source separately, you can just use
>> it as a normal dependency.
>> 
>> But if you want to view the source of a project in isolation I imagine any
>> common editor will suffice. Personally I'll tend to look where the source
>> is hosted (GitHub, GitLab etc) instead of downloading it. But I can
>> understand why some may not trust this.
>> 
>>> On Mon, 19 Aug 2019, 10:17 ,  wrote:
>>> 
>>> I like to download one package's source and study it in an editor. It
>>> allows me to open the whole package as a project and let me jump from a
>>> reference in one file to its definition in another file back and forth. It
>>> will be even better if it can handle the import modules too. (Maybe this is
>>> too much:-)
>>> 
>>> Can anyone recommend such a tool?
>>> 
>>> --Jach
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
>>> 
> 
> There is a free community version of PyCharm. Will it support the 
> cross-reference of viewing different files in different subdirectory? and 
> what Windows versions it requires? 
> 
> --Jach
> -- 
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which editor is suited for view a python package's source?

2019-08-20 Thread Bev In TX
Sorry, I meant to trim the older portion :-(

Bev in TX

> On Aug 20, 2019, at 4:53 AM, Bev In TX  wrote:
> 
> Search for “Choose” (without the quote marks) on the following webpage to see 
> the differences between the community and commercial versions:
> https://www.jetbrains.com/pycharm/features/
> 
> From the following webpage, “Microsoft Windows 7 SP1 or later”
> https://www.jetbrains.com/help/pycharm/installation-guide.html?_ga=2.186403823.798151923.1566294266-889030968.1566294266
> 
> Bev
> 
>> 
-- 
https://mail.python.org/mailman/listinfo/python-list


Is it able to connect remote win system from Linux using python

2019-08-20 Thread Iranna Mathapati
Hi Team,

can you please let me know , is there any module to  connect the remote
Windows system from Linux using python module?


Thanks,
Iranna M
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to login remote windos device using python

2019-08-20 Thread Iranna Mathapati
Thanks Kyle

Its working fine

On Tue, Aug 20, 2019 at 2:45 PM Iranna Mathapati 
wrote:

> Hi Kyle,
>
> I have tried with as per above attached links and it leads following error:
> NOTE: Its able to connect  local
>
> Failed to connect remote windows
> >>> import wmi
> >>> c = wmi.WMI("XX.XX.XX.XX", user=r"XXX\XXX", password="")
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "C:\Python27\lib\site-packages\wmi.py", line 1290, in connect
> handle_com_error ()
>   File "C:\Python27\lib\site-packages\wmi.py", line 241, in
> handle_com_error
> raise klass (com_error=err)
> wmi.x_wmi:  occurred.', (0, u'SWbemLocator', u'The RPC server is unavailable. ', None,
> 0, -2147023174), None)>
>
> On Tue, Aug 20, 2019 at 7:03 AM Kyle Stanley  wrote:
>
>> I would recommend checking out WMI: https://pypi.org/project/WMI/
>>
>> For remote connection as a named user (official WMI docs):
>> http://timgolden.me.uk/python/wmi/tutorial.html#connecting-to-a-remote-machine-as-a-named-user
>>
>> Also, another example (unofficial):
>> https://stackoverflow.com/questions/18961213/how-to-connect-to-a-remote-windows-machine-to-execute-commands-using-python.
>> This was done in Python2, but the example is still useful.
>>
>> On Mon, Aug 19, 2019 at 2:11 PM Iranna Mathapati 
>> wrote:
>>
>>> Hi Team,
>>>
>>> can you please let me know, How to login the remote Windows machine using
>>> python??
>>>
>>> Thanks
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
>>>
>>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is it able to connect remote win system from Linux using python

2019-08-20 Thread Chris Green
Iranna Mathapati  wrote:
> Hi Team,
> 
> can you please let me know , is there any module to  connect the remote
> Windows system from Linux using python module?
> 
We need more information, what sort of 'connect' to a remote Windows
system do you want?  I.e.:-

Do you want to run a Windows desktop remotely?

Do you want to send messages to the Windows machine?

Do you want to exchange files with the Windows machine?

Do you want to run a command line on the Windows machine?

... or something else?

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Enumerate - int object not subscriptable

2019-08-20 Thread Sayth Renshaw
Hi

I want to do basic math with a list.

a = [1, 2, 3, 4, 5, 6, 7, 8]

for idx, num in enumerate(a): 
print(idx, num)

This works, but say I want to print the item value at the next index as well as 
the current.

for idx, num in enumerate(a): 
print(num[idx + 1], num)

I am expecting 2, 1.

But am receiving 

TypeError: 'int' object is not subscriptable

Why?

Cheers

Sayth
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Enumerate - int object not subscriptable

2019-08-20 Thread Frank Millman

On 2019-08-20 2:00 PM, Sayth Renshaw wrote:

Hi

I want to do basic math with a list.

a = [1, 2, 3, 4, 5, 6, 7, 8]

for idx, num in enumerate(a):
 print(idx, num)

This works, but say I want to print the item value at the next index as well as 
the current.

for idx, num in enumerate(a):
 print(num[idx + 1], num)

I am expecting 2, 1.

But am receiving

TypeError: 'int' object is not subscriptable

Why?



I think you want a[idx+1], not num[idx+1].

Bear in mind that you will get IndexError for the last item in the list.

Frank Millman

--
https://mail.python.org/mailman/listinfo/python-list


Re: Enumerate - int object not subscriptable

2019-08-20 Thread BlindAnagram
On 20/08/2019 13:00, Sayth Renshaw wrote:
> Hi
> 
> I want to do basic math with a list.
> 
> 
> for idx, num in enumerate(a): 
> print(idx, num)
> 
> This works, but say I want to print the item value at the next index as well 
> as the current.
> 
> for idx, num in enumerate(a): 
> print(num[idx + 1], num)

a = [1, 2, 3, 4, 5, 6, 7, 8]
for idx, num in enumerate(a):
print(a[idx + 1], num)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Enumerate - int object not subscriptable

2019-08-20 Thread Cousin Stanley
Sayth Renshaw wrote:

> I want to do basic math with a list.
> 
> a = [1, 2, 3, 4, 5, 6, 7, 8]
> 
> for idx, num in enumerate(a):
> print(idx, num)
> 
> This works, but say I want to print the item value 
> at the next index as well as the current.
> 
> for idx, num in enumerate(a):
>
> print(num[idx + 1], num)
> 


#!/usr/bin/env python3

# sum each adjacent pair of elements in a list

ls = list( range( 10 , 1 , -1 ) ) 

print('\n  ' , ls , '\n' )

for enum , n in enumerate( range( len( ls ) - 1 ) ) :

i_left , i_rite = ls[ n : n + 2 ]

i_tot = i_left  +  i_rite

print( '  {:2d} :  {:2d}  +  {:2d} = {:4d} '.format( enum , i_left , i_rite 
, i_tot ) )


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is it able to connect remote win system from Linux using python

2019-08-20 Thread Iranna Mathapati
Hi Chris,

Want to run a command line on the remote windows machine [on powershell
command line] from linux device

I want to check what are the drivers are installed on the remote window
machine from a Linux machine using python.

Thanks,

On Tue, Aug 20, 2019 at 5:05 PM Chris Green  wrote:

> Iranna Mathapati  wrote:
> > Hi Team,
> >
> > can you please let me know , is there any module to  connect the remote
> > Windows system from Linux using python module?
> >
> We need more information, what sort of 'connect' to a remote Windows
> system do you want?  I.e.:-
>
> Do you want to run a Windows desktop remotely?
>
> Do you want to send messages to the Windows machine?
>
> Do you want to exchange files with the Windows machine?
>
> Do you want to run a command line on the Windows machine?
>
> ... or something else?
>
> --
> Chris Green
> ·
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Enumerate - int object not subscriptable

2019-08-20 Thread Ian Kelly
Or use the "pairwise" recipe from the itertools docs:

from itertools import tee

def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = tee(iterable)
next(b, None)
return zip(a, b)

for num1, num2 in pairwise(a):
print(num1, num2)

On Tue, Aug 20, 2019 at 7:42 AM Cousin Stanley 
wrote:

> Sayth Renshaw wrote:
>
> > I want to do basic math with a list.
> >
> > a = [1, 2, 3, 4, 5, 6, 7, 8]
> >
> > for idx, num in enumerate(a):
> > print(idx, num)
> >
> > This works, but say I want to print the item value
> > at the next index as well as the current.
> >
> > for idx, num in enumerate(a):
> >
> > print(num[idx + 1], num)
> > 
>
>
> #!/usr/bin/env python3
>
> # sum each adjacent pair of elements in a list
>
> ls = list( range( 10 , 1 , -1 ) )
>
> print('\n  ' , ls , '\n' )
>
> for enum , n in enumerate( range( len( ls ) - 1 ) ) :
>
> i_left , i_rite = ls[ n : n + 2 ]
>
> i_tot = i_left  +  i_rite
>
> print( '  {:2d} :  {:2d}  +  {:2d} = {:4d} '.format( enum , i_left ,
> i_rite , i_tot ) )
>
>
> --
> Stanley C. Kitching
> Human Being
> Phoenix, Arizona
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Xlabel and ylabel are not shown

2019-08-20 Thread David Lowry-Duda
There are two main ways of creating a plot in matplotlib: the pyplot 
MATLAB-style system and an object-oriented system. Although many 
tutorials online use the MATLAB interface, it is usually a good idea to 
use the object-oriented system.

I mention this here because after one calls `plt.plot()`, it can 
be a bit nonintuitive how to alter the plot through the MATLAB-style 
interface. I think this might be happening here.

If you provide a complete minimally-running-code sample, I'd be happy to 
go through it in a bit more detail.

- David Lowry-Duda
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: absolute path to a file

2019-08-20 Thread Paul St George

On 20/08/2019 11:43, Cameron Simpson wrote:

Please remember to CC the list.
Instead of 'Post a followup to this newsgroup' or 'To: 
[email protected]'?




On 19Aug2019 22:06, Paul St George  wrote:

On 19/08/2019 14:16, Cameron Simpson wrote:

[...]
There's a remark on that web page I mentioned that suggests that the 
leading '//' indicates the filename is relative to the Blender model, 
so the context directory for the '//' is likely 
/Users/Lion/Desktop/test8.


Yes. That makes sense. The reason I was testing with two images, one 
at /Users/Lion/Desktop/test8/image01.tif and the other at 
/Users/Lion/Desktop/images/image02.tif is that I cannot rely on images 
being in the same folder as the Blender file.


So, let's assume the context directory is /Users/Lion/Desktop/test8
and see how we get on below.

[...]
realpath needs a UNIX path. Your //image01.tif isn't a UNIX path, it 
is a special Blender path. First you need to convert it. By replacing 
'//' with the blend file's directory. Then you can call realpath. If 
you still need to.


Understood. Now. Thanks!


[...snip...]


Did you just [...snip...] yourself?


Yes. It keeps the surrounding context manageable. In this way you know 
to which text I am referring, without having to wade through paragraphs 
to guess what may be relevant.



   from os.path import dirname

   # Get this from somewhere just hardwiring it for the example.
   # Maybe from your 'n' object below?
   blend_file = '/Users/Lion/Desktop/test8/tifftest8.blend'

Is this setting a relative path?


   blender_image_file = n.image.filename

   unix_image_file = unblenderise(blender_image_file, 
dirname(blend_file))


Now you have a UNIX path. If blend_file is an absolute path, 
unix_image_path will also be an absolute path. But if blend_file is a 
relative path (eg you opened up "tifftest8.blend") unix_image_path 
will be a relative path.


Does unix_image_path = unix_image_file?


Yeah, sorry,  my mistake.


Two possibilities here.
blend_file (and so unix_image_file) is an absolute path OR blend_file 
(and so unix_image_file) is a relative path.


I just want to check my understanding. If I supply the path to 
blend_file then it is absolute, and if I ask Python to generate the 
path to blend_file from within Blender it is relative. Have I got it?


Not quite. What seems to be the situation is:

You've got some object from Blender called "n.image", which has a 
".file" attribute which is a Blender reference to the image file of the 
form "//image01.tif".


I presume that Blender has enough state inside "n" or "n.image" to 
locate this in the real filesystem; maybe it has some link to the 
Blender model of your blend file, and thus knows the path to the blend 
file and since //image01.tif is a reference relative to the blend file, 
it can construct the UNIX path to the file.


You want to know the UNIX pathname to the image file (maybe you want to 
pass it to some unrelated application to view the file or something).


Exactly. I am using Python to log a series of experiments. If I have a 
record of the settings and the assets used, I can better learn from what 
works and so repeat the successes and avoid the failures.


So you need to do what Blender would do if it needs a UNIX path (eg to 
open the file).


The formula for that is dirname(path_to_blendfile) with n.image.file[2:] 
appended to it. So that's what we do with unblenderise(): if the 
filename is a "Blender relative name", rip off the "//" and prepend the 
blend file directory path. That gets you a UNIX path which you can hand 
to any function expecting a normal operating system pathname.


Whether that is an absolute path or a relative path is entirely "does 
the resulting path start with a '/'"?


We used
blend_file = '/Users/Lion/Desktop/test8/tifftest8.blend'
So, if I read you correctly, this is an absolute path.

When we used unblenderise on it, out popped a path that was partly but 
not wholly relative. The latter half of the path is relative to the 
absolute first half (/Users/Lion/Desktop/test8/).


/Users/Lion/Desktop/test8/../images/image02.tif

It starts with a slash but cannot be pasted into "Go to...". But maybe 
that is an absolute path in UNIX?




An absolute path starts with a slash and is relative to the root of the 
filesystem. You can use such a path regardless of what your current 
working directory is, because it doesn't use the working directory.




A relative path doesn't start with a slash and is relative to the 
current working directory. It only works if you're in the right working 
directory.


_Because_ a relative path depends on the _your_ working directory, 
usually we pass around absolute paths if we need to tell something else 
about a file, because that will work regardless if what _their_ working 
directory may be.


So, you may well want to turn a relative path into an absolute path...

If I decided not to supply the path and so ended up with a relative 
UNIX path, I could now use 

Style suggestions/critiques

2019-08-20 Thread Michael F. Stemper
I recently wrote a couple of modules (more to come) to help me
use the tikz package in TeX/LaTeX. Since it's all to do with
drawing, I have a lot of points in R^2. Being unimaginative, I
implemented them as ordered pairs (2-tuples) of floats. E.g.:

p1 = 3,4
p2 = 5,6

Naturally, lines are implemented as ordered pairs[1] of points:

line = p1,p2

This all seems reasonably simple and intuitive (to me). However,
in order to actually do some manipulation, I have stuff like:

# Unpack the lines
l1p1,l1p2 = line1
l1x1,l1y1 = l1p1
l1x2,l1y2 = l1p2
l2p1,l2p2 = line2
l2x1,l2y1 = l2p1
l2x2,l2y2 = l2p2

spattered all over. Although this is simple enough, I find it
aesthetically unappealing.

Is there some better idiom that I should be using, or is this
really in accord with The Zen of Python?

[1] (I could have done sets, I suppose, but orientation might be
useful at some point.)

-- 
Michael F. Stemper
The FAQ for rec.arts.sf.written is at:
http://leepers.us/evelyn/faqs/sf-written
Please read it before posting.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: absolute path to a file

2019-08-20 Thread Cameron Simpson

On 20Aug2019 21:06, Paul St George  wrote:

On 20/08/2019 11:43, Cameron Simpson wrote:

Please remember to CC the list.
Instead of 'Post a followup to this newsgroup' or 'To: 
[email protected]'?


Hmm. I've been getting some of your posts directly to me as email with 
no obvious [email protected] to/cc header. Maybe some interaction 
with gmane? If you've been posting to the gmane newsgroup and CCing me 
privately that is likely fine, and I've misread the event (provided 
gmane backfeeds to the mailing list).


[...]

We used
blend_file = '/Users/Lion/Desktop/test8/tifftest8.blend'
So, if I read you correctly, this is an absolute path.

When we used unblenderise on it, out popped a path that was partly but 
not wholly relative. The latter half of the path is relative to the 
absolute first half (/Users/Lion/Desktop/test8/).


/Users/Lion/Desktop/test8/../images/image02.tif

It starts with a slash but cannot be pasted into "Go to...". But maybe 
that is an absolute path in UNIX?


Yes. It starts with a slash.

If you hand this to abspath it would fold out the "test8/.." part and 
give you a more direct absolute path.


And realpath would traverse the path looking for symlinks etc and fold 
out the same pair as a side effect of traversing the path.


But realpath is symlink aware. If test8 were a symlink to some remote 
part of the filesystem so that the TIF image were also elswhere, you'd 
get a direct path to that remote location.


For example, on our home server my ~/media directory is actually a 
symlink to an area on our 8TB RAID-1 volume:


   [~]borg*> pwd
   /home/cameron
   [~]borg*> ls -ld media
   lrwxrwxrwx 1 cameron cameron 9 Nov  2  2017 media -> 8TB/media

In fact "8TB" is also a symlink. So let's look:

   [~]borg*> python3
   Python 3.7.1 (default, Nov 14 2018, 10:38:43)
   [GCC 5.4.0 20160609] on linux
   Type "help", "copyright", "credits" or "license" for more information.
   >>> from os.path import abspath, realpath
   >>> abspath('media')
   '/home/cameron/media'
   >>> realpath('media')
   '/app8tb/cameron/media'

Both are valid absolute paths to the media directory.

Realpath has follwed the symlinks and given a direct route from '/' 
which does not go through any symlinks. Abspath has not bothered with 
such effort.


Cheers,
Cameron Simpson  (formerly [email protected])
--
https://mail.python.org/mailman/listinfo/python-list


Re: Which editor is suited for view a python package's source?

2019-08-20 Thread jfong
Nick Sarbicki於 2019年8月20日星期二 UTC+8下午1時33分32秒寫道:
> Yes the community edition works fine.
> 
> It seems to require a 64 bit version of Windows 7 or higher (I'm not sure
> as I haven't used Windows in years).
> 
> On Tue, 20 Aug 2019, 03:27 ,  wrote:
> 
> > Nick Sarbicki於 2019年8月19日星期一 UTC+8下午5時33分27秒寫道:
> > > PyCharm takes you to the source code within the editor for any
> > > variables/functions/classes/modules if you ctrl+click on what you want to
> > > see. It allows you to browse the relevant bits of code quickly, as well
> > as
> > > let you change them in your local environment if need be.
> > >
> > > That way you don't have to download the source separately, you can just
> > use
> > > it as a normal dependency.
> > >
> > > But if you want to view the source of a project in isolation I imagine
> > any
> > > common editor will suffice. Personally I'll tend to look where the source
> > > is hosted (GitHub, GitLab etc) instead of downloading it. But I can
> > > understand why some may not trust this.
> > >
> > > On Mon, 19 Aug 2019, 10:17 ,  wrote:
> > >
> > > > I like to download one package's source and study it in an editor. It
> > > > allows me to open the whole package as a project and let me jump from a
> > > > reference in one file to its definition in another file back and
> > forth. It
> > > > will be even better if it can handle the import modules too. (Maybe
> > this is
> > > > too much:-)
> > > >
> > > > Can anyone recommend such a tool?
> > > >
> > > > --Jach
> > > > --
> > > > https://mail.python.org/mailman/listinfo/python-list
> > > >
> >
> > There is a free community version of PyCharm. Will it support the
> > cross-reference of viewing different files in different subdirectory? and
> > what Windows versions it requires?
> >
> > --Jach
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >

Then, I can only download the older version 2016.2.3 for my old 32 bit 
system:-( 

--Jach
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: absolute path to a file

2019-08-20 Thread Richard Damon
On 8/20/19 5:56 PM, Cameron Simpson wrote:
>
> Hmm. I've been getting some of your posts directly to me as email with
> no obvious [email protected] to/cc header. Maybe some interaction
> with gmane? If you've been posting to the gmane newsgroup and CCing me
> privately that is likely fine, and I've misread the event (provided
> gmane backfeeds to the mailing list).

I think gmane feed the newsgroup comp.lang.python which feeds
[email protected]. Python-list probably then sees that you already
were getting a direct copy so omits sending you the duplicate.

-- 
Richard Damon

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which editor is suited for view a python package's source?

2019-08-20 Thread Kyle Stanley
> Then, I can only download the older version 2016.2.3 for my old 32 bit
system:-(

You could always use VSCode with the Python extension instead:
https://code.visualstudio.com/Download. There's support for 32bit Windows
as long as you're on 7, 8, or 10. I haven't used it myself though, I most
use the 64bit Linux version.

On Tue, Aug 20, 2019 at 9:30 PM  wrote:

> Nick Sarbicki於 2019年8月20日星期二 UTC+8下午1時33分32秒寫道:
> > Yes the community edition works fine.
> >
> > It seems to require a 64 bit version of Windows 7 or higher (I'm not sure
> > as I haven't used Windows in years).
> >
> > On Tue, 20 Aug 2019, 03:27 ,  wrote:
> >
> > > Nick Sarbicki於 2019年8月19日星期一 UTC+8下午5時33分27秒寫道:
> > > > PyCharm takes you to the source code within the editor for any
> > > > variables/functions/classes/modules if you ctrl+click on what you
> want to
> > > > see. It allows you to browse the relevant bits of code quickly, as
> well
> > > as
> > > > let you change them in your local environment if need be.
> > > >
> > > > That way you don't have to download the source separately, you can
> just
> > > use
> > > > it as a normal dependency.
> > > >
> > > > But if you want to view the source of a project in isolation I
> imagine
> > > any
> > > > common editor will suffice. Personally I'll tend to look where the
> source
> > > > is hosted (GitHub, GitLab etc) instead of downloading it. But I can
> > > > understand why some may not trust this.
> > > >
> > > > On Mon, 19 Aug 2019, 10:17 ,  wrote:
> > > >
> > > > > I like to download one package's source and study it in an editor.
> It
> > > > > allows me to open the whole package as a project and let me jump
> from a
> > > > > reference in one file to its definition in another file back and
> > > forth. It
> > > > > will be even better if it can handle the import modules too. (Maybe
> > > this is
> > > > > too much:-)
> > > > >
> > > > > Can anyone recommend such a tool?
> > > > >
> > > > > --Jach
> > > > > --
> > > > > https://mail.python.org/mailman/listinfo/python-list
> > > > >
> > >
> > > There is a free community version of PyCharm. Will it support the
> > > cross-reference of viewing different files in different subdirectory?
> and
> > > what Windows versions it requires?
> > >
> > > --Jach
> > > --
> > > https://mail.python.org/mailman/listinfo/python-list
> > >
>
> Then, I can only download the older version 2016.2.3 for my old 32 bit
> system:-(
>
> --Jach
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Style suggestions/critiques

2019-08-20 Thread Aldwin Pollefeyt
The Zen of Python is readability? Does this look neater?

x11, y11, x12, y12, x21, y21, x22, y22 = line1[0] + line1[1] + line2[0] +
line2[1]

Compared to tuples, lists are maybe more useful if you need to manipulate
the coordinates.

line1 = [ [1, 2], [3, 4] ]
line1[1][0] = 5
line1[0] = [2, 3]

or

_p1, _p2, _x, _y = 0, 1, 0, 1
line1 = [ [1, 2], [3, 4] ]
line1[_p2][_x] = 5
line1[_p1] = [2, 3]







On Wed, Aug 21, 2019 at 5:15 AM Michael F. Stemper <
[email protected]> wrote:

> I recently wrote a couple of modules (more to come) to help me
> use the tikz package in TeX/LaTeX. Since it's all to do with
> drawing, I have a lot of points in R^2. Being unimaginative, I
> implemented them as ordered pairs (2-tuples) of floats. E.g.:
>
> p1 = 3,4
> p2 = 5,6
>
> Naturally, lines are implemented as ordered pairs[1] of points:
>
> line = p1,p2
>
> This all seems reasonably simple and intuitive (to me). However,
> in order to actually do some manipulation, I have stuff like:
>
> # Unpack the lines
> l1p1,l1p2 = line1
> l1x1,l1y1 = l1p1
> l1x2,l1y2 = l1p2
> l2p1,l2p2 = line2
> l2x1,l2y1 = l2p1
> l2x2,l2y2 = l2p2
>
> spattered all over. Although this is simple enough, I find it
> aesthetically unappealing.
>
> Is there some better idiom that I should be using, or is this
> really in accord with The Zen of Python?
>
> [1] (I could have done sets, I suppose, but orientation might be
> useful at some point.)
>
> --
> Michael F. Stemper
> The FAQ for rec.arts.sf.written is at:
> http://leepers.us/evelyn/faqs/sf-written
> Please read it before posting.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: absolute path to a file

2019-08-20 Thread Grant Edwards
On 2019-08-21, Richard Damon  wrote:

> I think gmane feed the newsgroup comp.lang.python which feeds
> [email protected].

No, gmane is a gateway to [email protected].

--
Grant



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Style suggestions/critiques

2019-08-20 Thread DL Neil

On 21/08/19 9:11 AM, Michael F. Stemper wrote:

I recently wrote a couple of modules (more to come) to help me
use the tikz package in TeX/LaTeX. Since it's all to do with
drawing, I have a lot of points in R^2. Being unimaginative, I
implemented them as ordered pairs (2-tuples) of floats. E.g.:
p1 = 3,4
p2 = 5,6

Naturally, lines are implemented as ordered pairs[1] of points:
line = p1,p2

This all seems reasonably simple and intuitive (to me). However,
in order to actually do some manipulation, I have stuff like:
# Unpack the lines
l1p1,l1p2 = line1
l1x1,l1y1 = l1p1
l1x2,l1y2 = l1p2
l2p1,l2p2 = line2
l2x1,l2y1 = l2p1
l2x2,l2y2 = l2p2
spattered all over. Although this is simple enough, I find it
aesthetically unappealing.


Agreed, but could more descriptive names be used?



Is there some better idiom that I should be using, or is this
really in accord with The Zen of Python?
[1] (I could have done sets, I suppose, but orientation might be
useful at some point.)


Assuming that the code does-stuff with/to lines, eg rotate the line 0.2 
radians about some nominated rotational-center; maybe construct a class, eg


class Line():
def __init__( self, starting_point, ending_point ):
self.starting_point = starting_point
self.ending_point = ending_point
def rotate( self, angle, center ):
...

The same could also be said for a Point class. However, if they are 
'only' Cartesian coordinates and no methods ever apply(???), then maybe 
named-tuples or a dict?

(thus able to refer to p1.x and p1.y (or p1[ "x" ], etc) )


Using examples from above:

p1 = Point( 3, 4 )  # p1 = 3,4
p2 = Point( 5, 6 )  # p2 = 5,6

line = Line( p1, p2 )   # line = p1,p2

and instead of:
> l1p1,l1p2 = line1

Do things now appear to be closer to self-documenting?


Also, we can now use:
p1.x#instead of l1p1, and
p1.y#instead of l1p2

In fact, chances-are you won't ever do this because any point/line 
manipulation would become a method (hidden-away) within the respective 
class...

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Enumerate - int object not subscriptable

2019-08-20 Thread Sayth Renshaw
On Wednesday, 21 August 2019 03:16:01 UTC+10, Ian  wrote:
> Or use the "pairwise" recipe from the itertools docs:
> 
> from itertools import tee
> 
> def pairwise(iterable):
> "s -> (s0,s1), (s1,s2), (s2, s3), ..."
> a, b = tee(iterable)
> next(b, None)
> return zip(a, b)
> 
> for num1, num2 in pairwise(a):
> print(num1, num2)
> 

> > Stanley C. Kitching
> > Human Being
> > Phoenix, Arizona
> >
> > --

This definitely ended up being the ticket.

def pairwise(iterable): 
"s -> (s0,s1), (s1,s2), (s2, s3), ..." 
a, b = tee(iterable) 
next(b, None) 
return zip(a, b) 


def output_data(s):
serie = fibo(input_length)
x = []
y = []

for num1, num2 in pairwise(serie): 
y.append( num2 / num1) 

for item in y:
x.append(y.index(item))

draw_graph(x, y)


Kept trying with the enumerate style
for i, num in enumerate(serie):
while i < len(serie)-1:
x.append(int(serie[i + 1])/ int(serie[i]))
i += 1

but just couldn't quite get it to work. Itertools definitely made it easier.

for i, num in enumerate(serie):
while i < len(serie)-1:
x.append(int(serie[i + 1])/ int(serie[i]))
i += 1
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python requests get from API and post to another API and remote u'

2019-08-20 Thread Pankaj Jangid
Noah  writes:

> I place a get request and the response from the API is "{'id': 32,
> 'description': u'Firewall Outside', 'address': u'10.10.10.230/30'}"
>
> I then take that information and attempt post it to the other API.
> The data is not accepted and the result is an HTTP 400 code.
>
> I tried posting with postman and still rejected.
>
> I can post to the second API if I change the data to look like this:
> {"id": 32, "description": "Firewall Outside", "address":
> "10.10.10.230/30"}

This could be python version issue at your end. But I am thinking why
this is getting rejected by Postman as well. Try with vREST.

-- 
Pankaj Jangid
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: absolute path to a file

2019-08-20 Thread Paul St George

On 21/08/2019 04:09, Grant Edwards wrote:

On 2019-08-21, Richard Damon  wrote:


I think gmane feed the newsgroup comp.lang.python which feeds
[email protected].


No, gmane is a gateway to [email protected].

--
Grant

I use https://mail.python.org/pipermail/python-list/ to confirm that any 
post has gone where it should. And it has.



--
https://mail.python.org/mailman/listinfo/python-list