How to run self-contained Python scripts who don't need Python installation?

2017-06-08 Thread Juan C.
I need to run some Python 3.6.0 scripts on the users' machines (W7 and
W10) in an enterprise environment, but I can't install Python on those
machines. I tried looking for those "py to exe", but sadly they don't
support Python 3.6.0. Then I found out about "Windows x86/x86-64
embeddable zip file" that Python.org made available since 3.5.0, and I
thought it would be the right thing for my case.

I have some questions regarding embeddable Python:

1. How can I install custom modules using pip?

2. I'd like to create a simple BAT to run my Python script, so there
would be only 2 things (a 'dist' folder with everything and a run.bat
to make it clear what should be run), for example:
@echo off
start %~dp0dist\python-3.6.0-embed-win32\python.exe %~dp0dist\app.py

The issue is that I can't parse args to app.py in this case. How would
that be possible? In the example above, if Python was fully installed,
I would give a file as argument to app.py, generally clicking and
dragging the file into the app.py icon so that it would start.

3. Is there a better approach for my case other than embedded Python?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to create a Python 3.6 traceroute without SOCK RAW?

2017-02-23 Thread Juan C.
On Thu, Feb 23, 2017 at 7:42 PM, Irmen de Jong  wrote:
>
> import os
> os.system("traceroute www.google.com")

Indeed, that would work, but it isn't a great approach in my opinion
because I would rely on a system command, in this case Windows uses
tracert while UNIX uses traceroute, one could fix that with a if-else
to check the os and then use the correct command, but it just make it
feel even more like a workaround and not a definitive solution.
-- 
https://mail.python.org/mailman/listinfo/python-list


How to create a Python 3.6 traceroute without SOCK RAW?

2017-02-23 Thread Juan C.
I need to implement a traceroute inside my script but I can't escalate 
privileges.  Unix uses UDP for traceroute, but I didn't find any material 
regarding UDP traceroute in Python.


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


Re: What library/package to use for parsing XML?

2017-01-30 Thread Juan C.
On Mon, Jan 30, 2017 at 3:58 PM, Chris Green  wrote:
> I want to parse some XML data, it's the address book data from the
> linux program osmo.  The file I want to parse is like this:-

Just like Irmen said, use the default xml.etree.ElementTree, it's
amazing and very simple to use.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What are your opinions on .NET Core vs Python?

2017-01-30 Thread Juan C.
On Sun, Jan 29, 2017 at 1:06 AM, Juan C. <juan0christ...@gmail.com> wrote:
>
> As you guys might know, .NET Core is up and running, promising a 
> "cross-platform, unified, fast, lightweight, modern and open source 
> experience" (source: .NET Core official site). What do you guys think about 
> it? Do you think it will be able to compete with and overcome Python in the 
> opensource medium?

Oh, I forgot to say, I was indeed talking about .NET Core in general,
the framework, but I also had C#/ASP .NET Core in mind. The real
comparison here would be C#/ASP .NET Core vs Python/Django,Flask. I
personally had to work with C# a few times, it's a great language, but
my main problem was that it was Windows only and most of my personal
programs run on Linux. Yes, we have Mono, but it really didn't feel
"right" to me, it seemed like a workaround, I wanted something really
"native".

Python still has my heart, but .NET Core tempts me. One great thing of
coding in C# would be no GIL.
-- 
https://mail.python.org/mailman/listinfo/python-list


What are your opinions on .NET Core vs Python?

2017-01-28 Thread Juan C.
As you guys might know, .NET Core is up and running, promising a
"cross-platform, unified, fast, lightweight, modern and open source
experience" (source: .NET Core official site). What do you guys think about
it? Do you think it will be able to compete with and overcome Python in the
opensource medium?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.

2017-01-02 Thread Juan C.
On Mon, Jan 2, 2017 at 9:38 AM, Antonio Caminero Garcia <
tonycam...@gmail.com> wrote:
> The thing with the from-the-scratch full featured IDEs (Eclipse,
IntelliJ, Pycharm) is that they look like a space craft dashboard and that
unwarranted resources consumption and the unnecessary icons. I want my IDE
to be minimalistic but powerful. My screen should be mostly “made of code”
as usually happens in Vim, Sublime or Atom. However, Pycharm is really cool
and python oriented.

I use Sublime Text for small scripts and PyCharm Professional for bigger
projects and I don't find it resource heavy and the interface is simple
enough. You can pretty much hide all menus and sidebars on PyCharm and
you'd get pure code (it also has a "Distraction Free" mode), I suggest you
to read Pycharm's official doc to know a little more about it. My advice is
to NOT overthink it. IDEs and code editor are just tools, just pick one you
like and you're done.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python constructors have particular semantics, and ‘Foo.__init__’ doesn't qualify (was: The right way to 'call' a class attribute inside the same class)

2016-12-12 Thread Juan C.
I agree with you, I'll post here the same thing I said in there for
another member:

On Mon, Dec 12, 2016 at 6:59 PM, Thomas 'PointedEars' Lahn
 wrote:
> 
>

Using the Python official doc link you provided, it clearly states
that `__new__` is the one called to "create a new instance of class
[...] The return value of __new__() should be the new object instance
(usually an instance of cls)."

On the other hand, `__init__` is "called after the instance has been
created (by __new__()), but before it is returned to the caller."

Here we have the same mindset regarding `__new__` vs `__init__`:

- http://python-textbok.readthedocs.io/en/1.0/Classes.html
"Note: __init__ is sometimes called the object’s constructor, because
it is used similarly to the way that constructors are used in other
languages, but that is not technically correct – it’s better to call
it the initialiser. There is a different method called __new__ which
is more analogous to a constructor, but it is hardly ever used."

- http://www.python-course.eu/python3_object_oriented_programming.php
"We want to define the attributes of an instance right after its
creation. __init__ is a method which is immediately and automatically
called after an instance has been created. [...] The __init__ method
is used to initialize an instance."

- https://en.wikipedia.org/wiki/Constructor_(object-oriented_programming)#Python
"In Python, constructors are defined by one or both of __new__ and
__init__ methods. A new instance is created by calling the class as if
it were a function, which calls the __new__ and __init__ methods. If a
constructor method is not defined in the class, the next one found in
the class's Method Resolution Order will be called."

- http://www.diveintopython3.net/iterators.html
"The __init__() method is called immediately after an instance of the
class is created. It would be tempting — but technically incorrect —
to call this the “constructor” of the class. It’s tempting, because it
looks like a C++ constructor (by convention, the __init__() method is
the first method defined for the class), acts like one (it’s the first
piece of code executed in a newly created instance of the class), and
even sounds like one. Incorrect, because the object has already been
constructed by the time the __init__() method is called, and you
already have a valid reference to the new instance of the class."

In general, the idea is simple, `__new__` constructs and `__init__`
initializes, this is what I believe in, after all the name `__init__`
already tell us that it's a *init* ialiser...

It doesn't matter if Java, C#, Javascript,  have
different approaches, I'm programming (or at least, trying to :p) in
Python, so I'll follow what the official doc and the vast majority of
books/courses/etc say.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Juan C.
On Mon, Dec 12, 2016 at 6:59 PM, Thomas 'PointedEars' Lahn
 wrote:
> 

Using the Python official doc link you provided, it clearly states
that `__new__` is the one called to "create a new instance of class
[...] The return value of __new__() should be the new object instance
(usually an instance of cls)." On the other hand, `__init__` is
"called after the instance has been created (by __new__()), but before
it is returned to the caller."

Here we have the same mindset regarding `__new__` vs `__init__`:

- http://python-textbok.readthedocs.io/en/1.0/Classes.html
"Note: __init__ is sometimes called the object’s constructor, because
it is used similarly to the way that constructors are used in other
languages, but that is not technically correct – it’s better to call
it the initialiser. There is a different method called __new__ which
is more analogous to a constructor, but it is hardly ever used."

- http://www.python-course.eu/python3_object_oriented_programming.php
"We want to define the attributes of an instance right after its
creation. __init__ is a method which is immediately and automatically
called after an instance has been created. [...] The __init__ method
is used to initialize an instance."

- https://en.wikipedia.org/wiki/Constructor_(object-oriented_programming)#Python
"In Python, constructors are defined by one or both of __new__ and
__init__ methods. A new instance is created by calling the class as if
it were a function, which calls the __new__ and __init__ methods. If a
constructor method is not defined in the class, the next one found in
the class's Method Resolution Order will be called."

- http://www.diveintopython3.net/iterators.html
"The __init__() method is called immediately after an instance of the
class is created. It would be tempting — but technically incorrect —
to call this the “constructor” of the class. It’s tempting, because it
looks like a C++ constructor (by convention, the __init__() method is
the first method defined for the class), acts like one (it’s the first
piece of code executed in a newly created instance of the class), and
even sounds like one. Incorrect, because the object has already been
constructed by the time the __init__() method is called, and you
already have a valid reference to the new instance of the class."


In general, the idea is simple, `__new__` constructs and `__init__`
initializes, this is what I believe in, after all the name `__init__`
already tell us that it's a *init* ialiser...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Juan C.
On Mon, Dec 12, 2016 at 12:34 PM, Thomas 'PointedEars' Lahn
 wrote:
> First of all, the proper term for what you are doing there is _not_ “call”;
> you are _accessing_ an attribute instead.

Indeed, `accessing` seems better. I was looking for a better word but
couldn't find at the moment.

> To call something means generally in programming, and in Python, to execute
> it as a function instead: In the code above, the class object referred to by
> “Box” is called twice in order to instantiate twice (calling a class object
> in Python means to instantiate it, implicitly calling its constructor
> method, “__init__”, if any), and the global “print” function is called three
> times.

Since we are talking about Python terminology I believe that calling
`__init__` a constructor is also wrong. I've already seem some
discussions regarding it and the general consensus is that `__init__`
shouldn't be called constructor as it isn't really a constructor (like
Java/C# constructors). Some source:

- 
http://stackoverflow.com/questions/4859129/python-and-python-c-api-new-versus-init
- http://stackoverflow.com/questions/674304/pythons-use-of-new-and-init
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Juan C.
On Sun, Dec 11, 2016 at 11:34 PM, Steve D'Aprano
 wrote:

> So... in summary:
>
>
> When *assigning* to an attribute:
>
> - use `self.attribute = ...` when you want an instance attribute;
>
> - use `Class.attribute = ...` when you want a class attribute in
>   the same class regardless of which subclass is being used;
>
> - use `type(self).attribute = ...` when you want a class attribute
>   in a subclass-friendly way.
>
>
> When *retrieving* an attribute:
>
> - use `self.attribute` when you want to use the normal inheritance
>   rules are get the instance attribute if it exists, otherwise a
>   class or superclass attribute;
>
> - use `type(self).attribute` when you want to skip the instance
>   and always return the class or superclass attribute.

Thanks, that seems simple enough.
-- 
https://mail.python.org/mailman/listinfo/python-list


The right way to 'call' a class attribute inside the same class

2016-12-11 Thread Juan C.
I'm watching a Python course and was presented a topic regarding classes.
One of the examples were:

box.py

class Box:
serial = 100

def __init__(self, from_addr, to_addr):
self.from_addr = from_addr
self.to_addr = to_addr
self.serial = Box.serial
Box.serial += 1


from box import *

a = Box('19 Beech Ave. Seattle, WA 98144', '49 Carpenter Street North
Brunswick, NJ 08902')
b = Box('68 N. Church Dr. Vicksburg, MS 39180', '8 Lake Forest Road
Princeton, NJ 08540')

print(a.serial)  # print: 100
print(b.serial)  # print: 101
print(Box.serial)  # print: 102


The instructor said that the right way to call a class attribute is to use
'Class.class_attr' notation, but on the web I found examples where people
used 'self.class_attr' to call class attributes. I believe that using the
first notation is better ('Class.class_attr'), this way the code is more
explicit, but is there any rules regarding it?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to properly retrieve data using requests + bs4 from multiple pages in a site?

2016-12-03 Thread Juan C.
On Thu, Dec 1, 2016 at 10:07 PM, Juan C. <juan0christ...@gmail.com> wrote:
> It works, but it has a big issue: it gets all data from all
units/courses/assignments at the same time, and this isn't very useful as I
don't care about data from units from 1-2 years ago. How can I change the
logic so it just gets the data I need at a given moment? For example, I may
need to dump data for an entire unit, or just one course, or maybe even
just one assignment. How can I achieve this behavior? Another "issue", I
feel like handing my 'session' that I instantiated at user.py to program,
then unit, then course and then assignment is a poor design, how can I make
it better?
>
> Any other suggestions are welcome.

Oh, forgot to tell, I'm using Python 3.5.2 x64.
-- 
https://mail.python.org/mailman/listinfo/python-list


How to properly retrieve data using requests + bs4 from multiple pages in a site?

2016-12-01 Thread Juan C.
I'm a student and my university uses Moodle as their learning management
system (LMS). They don't have Moodle Web Services enabled and won't be
enabling it anytime soon, at least for students. The university programs
have the following structure, for example:

1. Bachelor's Degree in Computer Science (duration: 8 semesters)

1.1. Unit 01: Mathematics Fundamental (duration: 1 semester)
1.1.1. Algebra I (first 3 months)
1.1.2. Algebra II (first 3 months)
1.1.3. Calculus I (last 3 months)
1.1.4. Calculus II (last 3 months)
1.1.5. Unit Project (throughout the semester)

1.2. Unit 02: Programming (duration: 1 semester)
1.2.1. Programming Logic (first 3 months)
1.2.2. Data Modelling with UML (first 3 months)
1.2.3. Python I (last 3 months)
1.2.4. Python II (last 3 months)
1.2.5. Unit Project (throughout the semester)

Each course/project have a bunch of assignments + one final assignment.
This goes on, totalizing 8 (eight) units, which will make up for a 4-year
program. I'm building my own client-side Moodle API to be consumed by my
scripts. Currently I'm using 'requests' + 'bs4' to do the job. My code:

package moodle/

user.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from .program import Program
import requests


class User:
   _AUTH_URL = 'http://lms.university.edu/moodle/login/index.php'

   def __init__(self, username, password, program_id):
  self.username = username
  self.password = password
  session = requests.session()
  session.post(self._AUTH_URL, {"username": username, "password":
password})
  self.program = Program(program_id=program_id, session=session)

   def __str__(self):
  return self.username + ':' + self.password

   def __repr__(self):
  return '' % self.username

   def __eq__(self, other):
  if isinstance(other, self):
 return self.username == other.username
  else:
 return False

==

program.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from .unit import Unit
from bs4 import BeautifulSoup


class Program:
   _PATH = 'http://lms.university.edu/moodle/course/index.php?categoryid='

   def __init__(self, program_id, session):
  response = session.get(self._PATH + str(program_id))
  soup = BeautifulSoup(response.text, 'html.parser')

  self.name = soup.find('ul',
class_='breadcrumb').find_all('li')[-2].text.replace('/', '').strip()
  self.id = program_id
  self.units = [Unit(int(item['data-categoryid']), session) for item in
soup.find_all('div', {'class': 'category'})]

   def __str__(self):
  return self.name

   def __repr__(self):
  return '' % (self.name, self.id)

   def __eq__(self, other):
  if isinstance(other, self):
 return self.id == other.id
  else:
 return False

==

unit.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from .course import Course
from bs4 import BeautifulSoup


class Unit:
   _PATH = 'http://lms.university.edu/moodle/course/index.php?categoryid='

   def __init__(self, unit_id, session):
  response = session.get(self._PATH + str(unit_id))
  soup = BeautifulSoup(response.text, 'html.parser')

  self.name = soup.find('ul',
class_='breadcrumb').find_all('li')[-1].text.replace('/', '').strip()
  self.id = unit_id
  self.courses = [Course(int(item['data-courseid']), session) for item
in soup.find_all('div', {'class': 'coursebox'})]

   def __str__(self):
  return self.name

   def __repr__(self):
  return '' % (self.name, self.id)

   def __eq__(self, other):
  if isinstance(other, self):
 return self.id == other.id
  else:
 return False

==

course.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-


from .assignment import Assignment
import re
from bs4 import BeautifulSoup


class Course:
   _PATH = 'http://lms.university.edu/moodle/course/view.php?id='

   def __init__(self, course_id, session):
  response = session.get(self._PATH + str(course_id))
  soup = BeautifulSoup(response.text, 'html.parser')

  self.name = soup.find('h1').text
  self.id = course_id
  self.assignments = [Assignment(int(item['href'].split('id=')[-1]),
session) for item in
 soup.find_all('a', href=re.compile(r'http://lms
\.university\.edu/moodle/mod/assign/view.php\?id=.*'))]

   def __str__(self):
  return self.name

   def __repr__(self):
  return '' % (self.name, self.id)

   def __eq__(self, other):
  if isinstance(other, self):
 return self.id == other.id
  else:
 return False

==

assignment.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from bs4 import BeautifulSoup


class Assignment:
   _PATH = 'http://lms.university.edu/moodle/mod/assign/view.php?id='

   def __init__(self, assignment_id, session):
  response = session.get(self._PATH + str(assignment_id))
  soup = BeautifulSoup(response.text, 'html.parser')

  self.name = soup.find('h2').text
  self.id = assignment_id
  self.sent = soup.find('td', 

Re: Save session Selenium PhantomJS

2015-03-28 Thread Juan C.
Issue resolved.

My code was working, the problem was PhantomJS 2.0, used 1.9.8 and now I
have the 'cookies.txt' file as expected!
-- 
https://mail.python.org/mailman/listinfo/python-list


Save session Selenium PhantomJS

2015-03-26 Thread Juan C.
Objective: Save the browser session/cookies to share them in multiples
script execution.

I currently have this working using ChromeDriver:

chrome_options = Options()
chrome_options.add_argument(user-data-dir= + os.path.dirname(sys.argv[0]))
browser = webdriver.Chrome(chrome_options=chrome_options)

This code tells Chrome to use a specific path, in my case the script path,
as data folder where it stores everything, and NOT use the default
approach where everything is temporary and deleted when the script exits.

This way, I can login in the site I need once and exit the script. If I
execute the script later everything is already saved and I don't have to
login anymore.

I need this approach because the site has a security measure where they
send a key to my email everytime I login in a new PC.


The issue: Now I need to use PhantomJS. I already tried this code:

cookie_path = os.path.join(os.getcwd(), 'cookie.txt')
driver = webdriver.WebDriver(service_args=['--cookies-file=cookies.txt'])

But it doesn't work. I looked at the PhantomJS doc and on Google but didn't
find anything. I hope someone knows better than me and could give me a
hand here.

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


OpenID + Python 3.4

2015-03-24 Thread Juan C.
I was looking on the Internet regarding the use of OpenID in Python apps
but I only found Flask/web related stuff.

Is there any module that provides OpenID implementation for desktop level?

I currently have a Python desktop script that needs to authenticate in a
OpenID server, but I don't know how to implement it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Resource temporarily unavailable launching idle under cygwin

2006-08-08 Thread Juan C. Méndez
The rebase process worked. Thanks, Jason. The other previously posted solution of uninstalling and reinstalling Python did not. 

On 8/8/06, Jason Tishler [EMAIL PROTECTED] wrote:
Juan C.,On Mon, Aug 07, 2006 at 11:47:33AM -0700, jcmendez wrote: Hello everyone.Trying to run idle from a cygwin session on Win2k
 (yuk, but I must)I'm getting the following error message. [snip] $ idle 23367 [main] python2.4 1668 C:\cygwin\bin\python2.4.exe: *** fatal error - C:\cygwin\bin\python2.4.exe: *** unable to remap
 C:\cygwin\bin\tk84.dll to same address as parent(0x1889) != 0x18D2You need to rebase your system: http://www.google.com/search?hl=enq=cygwin+python+%22unable+to+remap%22
Jason--PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key serversFingerprint: 7A73 1405 7F2B E669 C19D8784 1AFD E4CC ECF4 8EF6

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