Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: [OT++] Seeking Win32 Python Wisdom

by thanos1983 (Parson)
on Mar 16, 2017 at 12:35 UTC ( [id://1184874]=note: print w/replies, xml ) Need Help??


in reply to [OT++] Seeking Win32 Python Wisdom

Hello syphilis,

Why don't you try to get the path and then convert it?

Sample of code:

#!/usr/bin/python import sysconfig sysconfig_output_before = sysconfig._getuserbase() sysconfig_output_after = '\\'.join(sysconfig_output_before.split('/')) print sysconfig_output_before print sysconfig_output_after

Sample of output:

/home/user/PythonVirtualEnvironment/bin/python /home/user/Downloads/Py +thonProject/test.py /home/user/.local \home\user\.local

Update: Maybe also this could help (Windows shell string operations (changing backslash to slash)). I do not have WindowsOS so I can not really test it (sorry).

Update2: I remember many many years ago when I was running WindowsOS I used to use (Cygwin). If I remember correctly it uses forward slashes, again (sorry) I do not have WindowsOS so I can not really test it.

Update3: In your case you have to reverse the parameters of course. I did not mention that before I did not thought that it is necessary.

Update4: I also found (Kernel::System::SysConfig - to manage sys config settings). I do not know if it helps but from the documentation is more or less what sysconfig — Provide access to Python’s configuration information. Just an idea. UnixOS

Update5: I also found (Win32::kernel32). I do not know if it helps but from the documentation: SearchPath can provide you:

1. the directory from which the application loaded. 2. the current directory 3. the Windows system directory 4. the Windows directory 5. the directories in the PATH environment variable

Just an idea and this is for. WindowsOS

Update6: Most likely you have thought about it already but just came into my mind. Why you do not execute your Python script and capture the output and convert it with Perl?

Sample of code:

#!/usr/bin/perl use strict; use warnings; my $path_before = qx(/home/user/Downloads/PythonProject/test.py 2>&1); print "Befofe: " . $path_before; my $path_new = $path_before; $path_new =~ s{/}{\\}g; # Use s/\\/\//g; print "After: " . $path_new; __END__ perl test_2.pl Befofe: /home/user/.local After: \home\user\.local

Hope this helps.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1184874]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-20 04:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found