save data from multiple txt files
Hi to everyone, I would save data from multiple files in one using pandas. below my script # Read results GCMG LAMMPS import pandas as pd import os import glob path = r"C:\Users\Documenti\Pyton\plot\results_CH4_180K\METHANE_180K_LJ_2.5-35.0_bar" os.chdir(path) results = pd.DataFrame() for counter, current_file in enumerate(glob.glob("results_*.log")): gcmcdatadf = pd.read_csv(current_file, header=2, sep=" ", usecols=[1, 2, 3]) print(gcmcdatadf) results = pd.concat([results, gcmcdatadf]) #results.to_csv('resuls_tot.log', header=None, sep=" ") In console I obtain Empty DataFrame Columns: [182.244, 10, 0.796176] Index: [] Empty DataFrame Columns: [181.126, 12.5, 0.995821] Index: [] Empty DataFrame Columns: [180.419, 15, 1.21188] Index: [] Empty DataFrame Columns: [179.8, 17.5, 1.43485] Index: [] Empty DataFrame Columns: [198.308, 2.5, 0.255925] Index: [] Empty DataFrame Columns: [179.68, 20, 1.65276] Index: [] Empty DataFrame Columns: [179.629, 22.5, 1.91916] Index: [] Empty DataFrame Columns: [179.838, 25, 2.20493] Index: [] Empty DataFrame Columns: [179.73, 27.5, 2.5408] Index: [] Empty DataFrame Columns: [179.645, 30, 2.98309] Index: [] Empty DataFrame Columns: [179.799, 32.5, 3.65617] Index: [] Empty DataFrame Columns: [180.184, 35, 22.3041] Index: [] Empty DataFrame Columns: [187.835, 5, 0.427784] Index: [] Empty DataFrame Columns: [183.896, 7.5, 0.606451] Index: [] #results.to_csv('resuls_tot.log', name=(T [K],)) How could I eliminate 'index:[]', an print results in one file as #T Pres Density 198.308, 2.5, 0.255925 . . . 180.184, 35, 22.3041 regards A. -- https://mail.python.org/mailman/listinfo/python-list
[issue45421] Remove dead code from html.parser
New submission from Alberto Mardegan : There appears to be some dead code in the html.parser module: https://github.com/python/cpython/blob/main/Lib/html/parser.py#L331-L337 Support for parser errors (with line and offset information) was removed long ago, so this code is useless now. The updatepos() and getpos() methods should also be removed. -- components: Library (Lib) messages: 403571 nosy: mardy priority: normal severity: normal status: open title: Remove dead code from html.parser type: enhancement ___ Python tracker <https://bugs.python.org/issue45421> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
convert script awk in python
Hi to everyone I have an awk script that calculate minimum distances between points ## atom type frag - atom type surface #!/bin/bash FILE1=$1.lammpstrj if [ -f $FILE1 ]; then awk 'function sq(x) { return x * x; } function dist(x1, y1, z1, x2, y2, z2) { return sqrt(sq(x1 - x2) + sq(y1 - y2) + sq(z1 - z2)); } function print_distances() { if (na == 0) print "No type 8 atoms."; else { min = 1000; for (a = 0; a < na; a++) { d = dist(x, y, z, pos[a,"x"], pos[a,"y"], pos[a,"z"]); #printf "%7.5f ", d; if (d < min) min = d; } printf "%6i%7.5f\n", istep, min; x = y = z = 0; delete pos; na = 0; } } $1 == 113 { if (x || y || z) print "More than one type $8 atom."; else { x = $2; y = $3; z = $4; istep++; } } $8 == 10 { pos[na,"x"] = $2; pos[na,"y"] = $3; pos[na,"z"] = $4; na += 1; } /^ITEM: ATOMS/ && na != 0 { print_distances(); } END { print_distances(); } ' $1.lammpstrj > $1_mindist.txt fi where $1 is a particular atom and $8 is a other type of atoms How could I prepare a python script regards A -- https://mail.python.org/mailman/listinfo/python-list
Re: program python
Il giorno giovedì 4 marzo 2021 alle 23:51:39 UTC+1 Igor Korot ha scritto: > Hi, > On Thu, Mar 4, 2021 at 4:42 PM alberto wrote: > > > > Il giorno giovedì 4 marzo 2021 alle 22:04:57 UTC+1 Paul Bryan ha scritto: > > > I don't see a Python program in that link. > > > > > > Are you asking how to extract data from a CSV? > > > A good start will be to look into the csv.reader function and > > > csv.DictReader class. > > > > > > Paul > > > On Thu, 2021-03-04 at 12:36 -0800, alberto wrote: > > > > Hi I'm tring to write a program with python to evaluate data of csv > > > > data > > > > In particular I would extract this information > > > > > > > > View data on the presence of men and women in Affori over time. > > > > > > > > * Carry out an analysis relating to the last available year. Of the > > > > 10 most populous neighborhoods show: > > > > * the proportion of births out of the total > > > > * the proportion of 80+ to the total > > > > * The ratio of minors / number of kindergartens > > > > > > > > this is the file > > > > https://drive.google.com/file/d/1zKflvSpB-oDAqYscLsEgUhSnqL1XPdql/view?usp=sharing > > > > > > > > > > > > How could fix it? > > > > > > > > regards > > > > Hi, > > with this code > > import pandas as pd > > df = pd.read_csv('data.csv',usecols=['Uomini','Donne']) > > > > print(df) > > I extract two columns, but I would see 'Affori over time' > And if you add this column to the list - what happens? > Thank you. > > > > > regards > > -- > > https://mail.python.org/mailman/listinfo/python-list Hi, with pandas I obtain results! Now I would calculate ratio beetween columns of my csv import pandas as pd pd.set_option('display.max_rows', 500) df = pd.read_csv ('data_quartiere_2018.csv', usecols= ['Anno','Totale','Quartiere','Nati','80 e più soli','80 e più','Minori','Scuola_infanzia (numero)']) test = df.loc[df['Totale'] >= 31990, print (test) in particular I would calculate ratio beetween ('Nati'*100)/'Totale' when ['Totale'] >= 31990 How could fix it -- https://mail.python.org/mailman/listinfo/python-list
Re: program python
Il giorno giovedì 4 marzo 2021 alle 22:04:57 UTC+1 Paul Bryan ha scritto: > I don't see a Python program in that link. > > Are you asking how to extract data from a CSV? > A good start will be to look into the csv.reader function and > csv.DictReader class. > > Paul > On Thu, 2021-03-04 at 12:36 -0800, alberto wrote: > > Hi I'm tring to write a program with python to evaluate data of csv > > data > > In particular I would extract this information > > > > View data on the presence of men and women in Affori over time. > > > > * Carry out an analysis relating to the last available year. Of the > > 10 most populous neighborhoods show: > > * the proportion of births out of the total > > * the proportion of 80+ to the total > > * The ratio of minors / number of kindergartens > > > > this is the file > > https://drive.google.com/file/d/1zKflvSpB-oDAqYscLsEgUhSnqL1XPdql/view?usp=sharing > > > > > > How could fix it? > > > > regards Hi, with this code import pandas as pd df = pd.read_csv('data.csv',usecols=['Uomini','Donne']) print(df) I extract two columns, but I would see 'Affori over time' regards -- https://mail.python.org/mailman/listinfo/python-list
program python
Hi I'm tring to write a program with python to evaluate data of csv data In particular I would extract this information View data on the presence of men and women in Affori over time. * Carry out an analysis relating to the last available year. Of the 10 most populous neighborhoods show: * the proportion of births out of the total * the proportion of 80+ to the total * The ratio of minors / number of kindergartens this is the file https://drive.google.com/file/d/1zKflvSpB-oDAqYscLsEgUhSnqL1XPdql/view?usp=sharing How could fix it? regards -- https://mail.python.org/mailman/listinfo/python-list
Asyncio Queue implementation suggestion
I have a suggestion about the implementation of asyncio queues that could improve performance. I might be missing something, however. I am sort of new to Python. Below a short description of the problem I am facing. I wrote a daemon in Python 3 (running in Linux) which test many devices at the same time, to be used in a factory environment. This daemon include multiple communication events to a back-end running in another country. I am using a class for each device I test, and embedded into the class I use asyncio. Due to the application itself and the number of devices tested simultaneously, I soon run out of file descriptor. Well, I increased the number of file descriptor in the application and then I started running into problems like “ValueError: filedescriptor out of range in select()”. I guess this problem is related to a package called serial_asyncio, and of course, that could be corrected. However I became curious about the number of open file descriptors opened: why so many? Apparently asyncio Queues use a Linux pipe and each queue require 2 file descriptors. Am I correct? So I asked my self: if a asyncio queue is just a mechanism of piping information between two asyncio tasks, which should never run at the same time, why do I need the operating system in the middle of that? Isn’t the whole idea about asyncio that the operating system would be avoided whenever possible? No one will put anything into a queue if asyncio called epoll, because some Python code should be running to push things into the queue. If there is nothing in a particular queue, nothing will show up while asyncio is waiting for a file descriptor event. So, if I am correct, it would be more efficient to put the queue in a ready-queue list whenever something is pushed into it. Then, just before asyncio calls epoll (or select), it would check that ready queue, and it would process it before the epoll call. I mean that epoll would not be called unless all the queues have been properly processed. Queues would be implemented in a much simpler way, using local memory: a simple array may be enough to do the job. With that the OS would be avoided, and a much lower number of file descriptors would be necessary. -- https://mail.python.org/mailman/listinfo/python-list
[issue40982] copytree example in shutil
New submission from Alberto Torres Barrán : The copytree example in https://docs.python.org/3/library/shutil.html#copytree-example does not match the source code, even removing docstrings. In particular is missing parameters and the exceptions are in the wrong order (Error will never be reachable since it is n instance of OSError). -- assignee: docs@python components: Documentation messages: 371535 nosy: Alberto Torres Barrán, docs@python priority: normal severity: normal status: open title: copytree example in shutil versions: Python 3.8 ___ Python tracker <https://bugs.python.org/issue40982> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
HYDRASPA error
hi, my name is Alberto Now I'm trying to install and use the code hydraspa (https://pypi.org/project/hydraspa/) I'm installing from source with command python 3.5 setup.py install but when I run hydraspa create -s IRMOF-1 -g CO2 -f UFF -o myCO2sim as reported in documentation I obtain TEST_RASPA $ hydraspa create -s IRMOF-1.cif -g CO2.def -f uff.def -o myCO2sim Traceback (most recent call last): File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 417, in get_provider module = sys.modules[moduleOrReq] KeyError: None During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/bin/hydraspa", line 4, in __import__('pkg_resources').run_script('hydraspa==0.3.1', 'hydraspa') File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 719, in run_script self.require(requires)[0].run_script(script_name, ns) File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1511, in run_script exec(script_code, namespace, namespace) File "/usr/local/lib/python3.5/dist-packages/hydraspa-0.3.1-py3.5.egg/EGG-INFO/scripts/hydraspa", line 7, in File "", line 969, in _find_and_load File "", line 958, in _find_and_load_unlocked File "", line 664, in _load_unlocked File "", line 634, in _load_backward_compatible File "/usr/local/lib/python3.5/dist-packages/hydraspa-0.3.1-py3.5.egg/hydraspa/__init__.py", line 5, in File "", line 969, in _find_and_load File "", line 958, in _find_and_load_unlocked File "", line 664, in _load_unlocked File "", line 634, in _load_backward_compatible File "/usr/local/lib/python3.5/dist-packages/hydraspa-0.3.1-py3.5.egg/hydraspa/files.py", line 28, in File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1189, in resource_listdir return get_provider(package_or_requirement).resource_listdir( File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 419, in get_provider __import__(moduleOrReq) TypeError: __import__() argument 1 must be str, not None regards Alberto -- https://mail.python.org/mailman/listinfo/python-list
Re: insert data in python script
Il giorno martedì 18 febbraio 2020 11:01:11 UTC+1, David ha scritto: > On Tue, 18 Feb 2020 at 20:45, alberto wrote: > > Il giorno martedì 18 febbraio 2020 09:34:51 UTC+1, DL Neil ha scritto: > > > > > my code preos in one file preos.py > > > > my commands are > > > > > > > > alberto@HENDRIX ~/PREOS $ python3.5 > > > > Python 3.5.2 (default, Oct 8 2019, 13:06:37) > > > > [GCC 5.4.0 20160609] on linux > > > > Type "help", "copyright", "credits" or "license" for more information. > > > >>>> import preos > > > >>>> methane = Molecule("methane", -82.59 + 273.15, 45.99, 0.011) > > > > Traceback (most recent call last): > > > >File "", line 1, in > > > > NameError: name 'Molecule' is not defined > > > honestly i don't understand what i have to do. > > $ python3 > Python 3.5.3 (default, Sep 27 2018, 17:25:39) > [GCC 6.3.0 20170516] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> print(digits) > Traceback (most recent call last): > File "", line 1, in > NameError: name 'digits' is not defined > >>> print(string.digits) > Traceback (most recent call last): > File "", line 1, in > NameError: name 'string' is not defined > >>> import string > >>> print(digits) > Traceback (most recent call last): > File "", line 1, in > NameError: name 'digits' is not defined > >>> print(string.digits) > 0123456789 > >>> Hi, I solve it with external file as follows import preos # pass name, Tc, Pc, omega methane = preos.Molecule("methane", -82.59 + 273.15, 45.99, 0.011) methane.print_params() thanks to everyone regards Alberto -- https://mail.python.org/mailman/listinfo/python-list
Re: insert data in python script
Il giorno martedì 18 febbraio 2020 09:34:51 UTC+1, DL Neil ha scritto: > ... > > >> import preos > >> # pass name, Tc, Pc, omega > >> methane = preos.Molecule("methane", -82.59 + 273.15, 45.99, 0.011) > >> methane.print_params() > > ... > > > my code preos in one file preos.py > > my commands are > > > > alberto@HENDRIX ~/PREOS $ python3.5 > > Python 3.5.2 (default, Oct 8 2019, 13:06:37) > > [GCC 5.4.0 20160609] on linux > > Type "help", "copyright", "credits" or "license" for more information. > >>>> import preos > >>>> methane = Molecule("methane", -82.59 + 273.15, 45.99, 0.011) > > Traceback (most recent call last): > >File "", line 1, in > > NameError: name 'Molecule' is not defined > > > The first instruction (immediately above) imports the module preos.py. > That works (no error message!). > > The second instruction refers to a Python class called Molecule. That > fails. The error message says that 'Molecule' is not defined. > > Yet we can 'see' it. It *has* been defined! What is going on??? > > In this case, we need to tell Python that Molecule is part of the preos > module. So back to your original code (top): > > methane = preos.Molecule("methane", -82.59 + 273.15, 45.99, 0.011) > > > Please refer to earlier message. If Module were called from code in the > preos.py file, then the "preos." prefix would not be necessary. > > The formal term for this situation is "namespaces". Because Molecule is > defined within the preos.py module's namespace we need to tell Python > exactly where Molecule can be found. In the same way that we might say: > if someone in Antarctica wants to see Alberto, (s)he will have to go to > Italy to find him... > > > Don't hesitate to say if you think my reply is too complicated/advanced. > People here are happy to help... > -- > Regards =dn hi honestly i don't understand what i have to do. I have been using python for too little time. could you help me understand regards Alberto -- https://mail.python.org/mailman/listinfo/python-list
Re: insert data in python script
Il giorno lunedì 17 febbraio 2020 17:48:07 UTC+1, alberto ha scritto: > Hi, > I would use this script to evaluate fugacity coefficient with PENG-ROBINSON > equation, but I don't understand the correct mode to insert data > > import numpy as np > import matplotlib.pyplot as plt > from scipy.optimize import newton > > R = 8.314e-5 # universal gas constant, m3-bar/K-mol > class Molecule: > """ > Store molecule info here > """ > def __init__(self, name, Tc, Pc, omega): > """ > Pass parameters desribing molecules > """ > #! name > self.name = name > #! Critical temperature (K) > self.Tc = Tc > #! Critical pressure (bar) > self.Pc = Pc > #! Accentric factor > self.omega = omega > > def print_params(self): > """ > Print molecule parameters. > """ > print("""Molecule: %s. > \tCritical Temperature = %.1f K > \tCritical Pressure = %.1f bar. > \tAccentric factor = %f""" % (self.name, self.Tc, self.Pc, > self.omega)) > > def preos(molecule, T, P, plotcubic=True, printresults=True): > """ > Peng-Robinson equation of state (PREOS) > > http://en.wikipedia.org/wiki/Equation_of_state#Peng.E2.80.93Robinson_equation_of_state > :param molecule: Molecule molecule of interest > :param T: float temperature in Kelvin > :param P: float pressure in bar > :param plotcubic: bool plot cubic polynomial in compressibility factor > :param printresults: bool print off properties > Returns a Dict() of molecule properties at this T and P. > """ > # build params in PREOS > Tr = T / molecule.Tc # reduced temperature > a = 0.457235 * R**2 * molecule.Tc**2 / molecule.Pc > b = 0.0777961 * R * molecule.Tc / molecule.Pc > kappa = 0.37464 + 1.54226 * molecule.omega - 0.26992 * molecule.omega**2 > alpha = (1 + kappa * (1 - np.sqrt(Tr)))**2 > > A = a * alpha * P / R**2 / T**2 > B = b * P / R / T > > # build cubic polynomial > def g(z): > """ > Cubic polynomial in z from EOS. This should be zero. > :param z: float compressibility factor > """ > return z**3 - (1 - B) * z**2 + (A - 2*B - 3*B**2) * z - ( > A * B - B**2 - B**3) > > # Solve cubic polynomial for the compressibility factor > z = newton(g, 1.0) # compressibility factor > rho = P / (R * T * z) # density > > # fugacity coefficient comes from an integration > fugacity_coeff = np.exp(z - 1 - np.log(z - B) - A / np.sqrt(8) / B * > np.log( > (z + (1 + np.sqrt(2)) * B) / (z + (1 - np.sqrt(2)) * B))) > > if printresults: > print("""PREOS calculation at > \t T = %.2f K > \t P = %.2f bar""" % (T, P)) > print("\tCompressibility factor : ", z) > print("\tFugacity coefficient: ", fugacity_coeff) > print("\tFugacity at pressure %.3f bar = %.3f bar" % ( > P, fugacity_coeff * P)) > print("\tDensity: %f mol/m3" % rho) > print("\tMolar volume: %f L/mol" % (1.0 / rho * 1000)) > print("\tDensity: %f v STP/v" % (rho * 22.4 / 1000)) > print("\tDensity of ideal gas at same conditions: %f v STP/v" % ( > rho * 22.4/ 1000 * z)) > > if plotcubic: > # Plot the cubic equation to visualize the roots > zz = np.linspace(0, 1.5) # array for plotting > > plt.figure() > plt.plot(zz, g(zz), color='k') > plt.xlabel('Compressibility, $z$') > plt.ylabel('Cubic $g(z)$') > plt.axvline(x=z) > plt.axhline(y=0) > plt.title('Root found @ z = %.2f' % z) > plt.show() > return {"density(mol/m3)": rho, "fugacity_coefficient": fugacity_coeff, > "compressibility_factor": z, "fugacity(bar)": fugacity_coeff * P, > "molar_volume(L/mol)": 1.0 / rho * 1000.0} > > def preos_reverse(molecule, T, f, plotcubic=False, printresults=True): > """ > Reverse Peng-Robinson equation of state (PREOS) to obtain pressure for a > particular fugacity > :param molecule: Molecule molecule of interest > :param T: float temperature in Kelvin > :param f: float fugacity in bar > :param plotcub
fugacity cofficient
Hi, how I could realize a script to calculate fugacity coefficients with this formula https://wikimedia.org/api/rest_v1/media/math/render/svg/8743fb5a1e85edb8f4334fb7154727057f395eb8 in my input file.txt I have this data #p z 10.0 0.9850 20.0 0.9703 30.0 0.9560 40.0 0.9421 50.0 0.9287 regards Alberto -- https://mail.python.org/mailman/listinfo/python-list
insert data in python script
tcubic, printresults=printresults) rho = pars["density(mol/m3)"] fugacity_coeff = pars["fugacity_coefficient"] z = pars["compressibility_factor"] return {"density(mol/m3)": rho, "fugacity_coefficient": fugacity_coeff, "compressibility_factor": z, "pressure(bar)": P, "molar_volume(L/mol)": 1.0 / rho * 1000.0} # TODO: Implement mixture in object-oriented way as well def preos_mixture(molecule_a, molecule_b, delta, T, P_total, x, plotcubic=True, printresults=True): """ Peng-Robinson equation of state (PREOS) for a binary mixture http://en.wikipedia.org/wiki/Equation_of_state#Peng.E2.80.93Robinson_equation_of_state :param molecule_a: Molecule molecule 1 of interest :param molecule_b: Molecule molecule 2 of interest :param delta: binary interaction parameter between molecules a and b :param T: float temperature in Kelvin :param P_total: float total pressure in bar :param x: array mole fractions :param plotcubic: bool plot cubic polynomial in compressibility factor :param printresults: bool print off properties """ # build arrays of properties Tc = np.array([molecule_a.Tc, molecule_b.Tc]) Pc = np.array([molecule_a.Pc, molecule_b.Pc]) omega = np.array([molecule_a.omega, molecule_b.omega]) # build params in PREOS Tr = T / Tc # reduced temperature a0 = 0.457235 * R**2 * Tc**2 / Pc b = 0.0777961 * R * Tc / Pc kappa = 0.37464 + 1.54226 * omega - 0.26992 * omega**2 a = a0 * (1 + kappa * (1 - np.sqrt(Tr)))**2 # apply mixing rules aij = (1.0 - delta) * np.sqrt(a[0] * a[1]) a_mix = a[0] * x[0]**2 + a[1] * x[1]**2 + 2.0 * x[0] * x[1] * aij b_mix = x[0] * b[0] + x[1] * b[1] A = a_mix * P_total / R**2 / T**2 B = b_mix * P_total / R / T # build cubic polynomial def g(z): """ Cubic polynomial in z from EOS. This should be zero. :param z: float compressibility factor """ return z**3 - (1 - B) * z**2 + (A - 2*B - 3*B**2) * z - ( A * B - B**2 - B**3) # Solve cubic polynomial for the compressibility factor z = newton(g, 1.0) # compressibility factor rho = P_total / (R * T * z) # density Lnfug_0 = -np.log(z - B) + (z - 1.0) * b[0] / b_mix - A / np.sqrt(8) / B * (2.0 / a_mix * (x[0] * a[0] + x[1] * aij) - b[0] / b_mix) *\ np.log((z + (1.0 + np.sqrt(2)) * B) / (z + (1.0 - np.sqrt(2)) * B)) Lnfug_1 = -np.log(z - B) + (z - 1.0) * b[1] / b_mix - A / np.sqrt(8) / B * (2.0 / a_mix * (x[1] * a[1] + x[0] * aij) - b[1] / b_mix) *\ np.log((z + (1.0 + np.sqrt(2)) * B) / (z + (1.0 - np.sqrt(2)) * B)) # fugacity coefficient comes from an integration fugacity_coefs = np.exp(np.array([Lnfug_0, Lnfug_1])) if printresults: print("""PREOS calculation at \t T = %.2f K \t P, total = %.2f bar""" % (T, P_total)) print("\tDensity: %f mol/m3" % rho) print("\tCompressibility factor : %f" % z) print("Component 0, %s:" % molecule_a.name) print("\tFugacity coefficient: %f" % fugacity_coefs[0]) print("\tFugacity: %f bar" % (fugacity_coefs[0] * x[0] * P_total)) print("Component 1, %s:" % molecule_b.name) print("\tFugacity coefficient: %f" % fugacity_coefs[1]) print("\tFugacity: %f bar" % (fugacity_coefs[1] * x[1] * P_total)) if plotcubic: # Plot the cubic equation to visualize the roots zz = np.linspace(0, 1.5) # array for plotting plt.figure() plt.plot(zz, g(zz), color='k') plt.xlabel('Compressibility, $z$') plt.ylabel('Cubic $g(z)$') plt.axvline(x=z) plt.axhline(y=0) plt.title('Root found @ z = %.2f' % z) plt.show() return {"density(mol/m3)": rho, "fugacity_coefficients": fugacity_coefs, "compressibility_factor": z} the readme file says that As an example calculation, we consider methane at 65.0 bar and 298.0 K. Methane has a critical temperature of -82.59 deg. C and a critical pressure of 45.99 bar. Its accentric factor is 0.011. We first create a methane molecule object and print its stored parameters: import preos # pass name, Tc, Pc, omega methane = preos.Molecule("methane", -82.59 + 273.15, 45.99, 0.011) methane.print_params() Could I fix it regards Alberto -- https://mail.python.org/mailman/listinfo/python-list
[issue39293] Windows 10 64-bit needs reboot after install
Change by Alberto N Leilani Campos : Added file: https://bugs.python.org/file48854/windows-ssh-tools.snapshot.json ___ Python tracker <https://bugs.python.org/issue39293> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
install software
Hi, I'm trying to install a python source https://github.com/peteboyd/lammps_interface when I run the example test I receive this error AttributeError: 'NoneType' object has no attribute 'copy' How could I fix it? regards lammps-interface /home/alberto/Scaricati/lammps_interface-master/test_struct/IRMOF-1.cif fatal: Not a git repository (or any of the parent directories): .git No bonds reported in cif file - computing bonding.. Molecules found in the framework, separating. Traceback (most recent call last): File "/usr/local/bin/lammps-interface", line 4, in __import__('pkg_resources').run_script('lammps-interface==0.1.1', 'lammps-interface') File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 719, in run_script self.require(requires)[0].run_script(script_name, ns) File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1504, in run_script exec(code, namespace, namespace) File "/usr/local/lib/python3.5/dist-packages/lammps_interface-0.1.1-py3.5.egg/EGG-INFO/scripts/lammps-interface", line 13, in sim.split_graph() File "/usr/local/lib/python3.5/dist-packages/lammps_interface-0.1.1-py3.5.egg/lammps_interface/lammps_main.py", line 398, in split_graph sg = self.cut_molecule(molecule) File "/usr/local/lib/python3.5/dist-packages/lammps_interface-0.1.1-py3.5.egg/lammps_interface/lammps_main.py", line 1535, in cut_molecule mgraph.distance_matrix = self.graph.distance_matrix.copy() AttributeError: 'NoneType' object has no attribute 'copy' the installetion seems completed correctly sudo python3 setup.py install /usr/lib/python3.5/distutils/dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type' warnings.warn(msg) running install Checking .pth file support in /usr/local/lib/python3.5/dist-packages/ /usr/bin/python3 -E -c pass TEST PASSED: /usr/local/lib/python3.5/dist-packages/ appears to support .pth files running bdist_egg running egg_info creating lammps_interface.egg-info writing requirements to lammps_interface.egg-info/requires.txt writing dependency_links to lammps_interface.egg-info/dependency_links.txt writing lammps_interface.egg-info/PKG-INFO writing top-level names to lammps_interface.egg-info/top_level.txt writing manifest file 'lammps_interface.egg-info/SOURCES.txt' reading manifest file 'lammps_interface.egg-info/SOURCES.txt' writing manifest file 'lammps_interface.egg-info/SOURCES.txt' installing library code to build/bdist.linux-x86_64/egg running install_lib running build_py creating build creating build/lib creating build/lib/lammps_interface copying lammps_interface/mof_sbus.py -> build/lib/lammps_interface copying lammps_interface/Dubbeldam.py -> build/lib/lammps_interface copying lammps_interface/gas_models.py -> build/lib/lammps_interface copying lammps_interface/lammps_main.py -> build/lib/lammps_interface copying lammps_interface/structure_data.py -> build/lib/lammps_interface copying lammps_interface/Molecules.py -> build/lib/lammps_interface copying lammps_interface/water_models.py -> build/lib/lammps_interface copying lammps_interface/lammps_potentials.py -> build/lib/lammps_interface copying lammps_interface/BTW.py -> build/lib/lammps_interface copying lammps_interface/dreiding.py -> build/lib/lammps_interface copying lammps_interface/CIFIO.py -> build/lib/lammps_interface copying lammps_interface/__init__.py -> build/lib/lammps_interface copying lammps_interface/generic_raspa.py -> build/lib/lammps_interface copying lammps_interface/atomic.py -> build/lib/lammps_interface copying lammps_interface/ccdc.py -> build/lib/lammps_interface copying lammps_interface/uff_nonbonded.py -> build/lib/lammps_interface copying lammps_interface/MOFFF.py -> build/lib/lammps_interface copying lammps_interface/uff.py -> build/lib/lammps_interface copying lammps_interface/InputHandler.py -> build/lib/lammps_interface copying lammps_interface/uff4mof.py -> build/lib/lammps_interface copying lammps_interface/ForceFields.py -> build/lib/lammps_interface creating build/bdist.linux-x86_64 creating build/bdist.linux-x86_64/egg creating build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/mof_sbus.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/Dubbeldam.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/gas_models.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/lammps_main.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/structure_data.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/Molecules.py -> build/bdist.linux-x86_64/egg/lammps_interface copying build/lib/lammps_interface/water_models.py -> build/bdist.linux-x86_64/
TypeError: loadtxt() got an unexpected keyword argument 'max_rows'
Hi, I produce a script to elaborate data but command line $ python3.4 PlotnhvsvdBTP1.py I have this error Traceback (most recent call last): File "PlotnhvsvdBTP1.py", line 31, in UCvol = np.loadtxt(outputtransfile,skiprows=26,max_rows=1,usecols=[1]) TypeError: loadtxt() got an unexpected keyword argument 'max_rows' How could fix it? I attacched my files https://drive.google.com/file/d/1PgOcuEMFsaAuKTsbU0i0gwg04mDCJJoK/view?usp=sharing https://drive.google.com/file/d/13E7vcGQtrOS1lw9RupGThGQ2vSGRfTFG/view?usp=sharing https://drive.google.com/file/d/1Z6GKYtHthAyPO3wFHUFK10QweRpclu29/view?usp=sharing regard Alberto -- https://mail.python.org/mailman/listinfo/python-list
[issue34951] cookielib/cookiejar cookies' Expires date parse fails with long month names
Alberto Moral added the comment: Yes, I was thinking that it could be a matter of configuration of the server (?). By the way, and just for fun, I've just realized that truncating mon at the begining of the _str2time funtion is a very bad idea because mon could also be an int. A better place is when looking the MONTHS_LOWER array index (and possible exception is handle): try: mon = MONTHS_LOWER.index(mon[:3].lower())+1 (perhaps in 2 sentences for clarity) OK, waiting for experts' comments. I'm really enjoying Python. -- ___ Python tracker <https://bugs.python.org/issue34951> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue34951] cookielib/cookiejar cookies' Expires date parse fails with long month names
Alberto Moral added the comment: Thanks for your answer. I have not found any RFCs with full month names either. I'm afraid I'm not an expert here. But the case is that I get them in my work. Here is an example of response header: HTTP/1.1 200 OK Server: Oracle-iPlanet-Web-Server/7.0 Date: Tue, 10 Oct 2018 14:29:44 GMT Version-auth-credencial: v.3.0.1 Iplanet - Sun Solaris - Contexto Multiple Set-cookie: JSESSIONIDE=Del; expires=Friday, 1-August-1997 00:00:00 GMT; domain=... I do not know if it's an old date format (?)... or if it is a quite rare case... I have created some previous bash scripts using wget and they work fine, but I have had problems with python3 (and requests module) till I realized this issue. And it was not very easy: I am very new with python :( That's the reason of my proposal. It's just to be coherent: if we compare 3 letters of a month with MONTHS_LOWER, let's use just 3 (first) letters. Perhaps modifying LOOSE_HTTP_DATE_RE is not a good idea. Another option could be to truncate the month variable (mon). It could be done inside the _str2time funtion, for example: def _str2time(day, mon, yr, hr, min, sec, tz): mon = mon[:3] # assure 3 letters yr = int(yr) Anyway, I'll try to find why those long month names appear. Thank you -- ___ Python tracker <https://bugs.python.org/issue34951> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue34951] cookielib/cookiejar cookies' Expires date parse fails with long month names
New submission from Alberto Moral : http.cookiejar (cookielib, for python2.*) does not parse some cookies' Expires date. For example: "Friday, 1-August-1997 00:00:00 GMT" does not work (while: "Fri, 01 Aug 1997 00:00:00 GMT" works fine) This is basically due to long names of months (it is compared with MONTHS_LOWER: list of 3-letter months). So, I propose a small change in the definition of LOOSE_HTTP_DATE_RE (see fifth line): LOOSE_HTTP_DATE_RE = re.compile( r"""^ (\d\d?)# day (?:\s+|[-\/]) (\w{3})\w* # month (3 first letters only) ... Instead of: LOOSE_HTTP_DATE_RE = re.compile( r"""^ (\d\d?)# day (?:\s+|[-\/]) (\w+) # month ... I've tested only http.cookiejar (python 3.6), but I suposse the same change will work on cookielib Thanks in advance -- components: Library (Lib) messages: 327461 nosy: alb_moral priority: normal severity: normal status: open title: cookielib/cookiejar cookies' Expires date parse fails with long month names type: behavior versions: Python 2.7, Python 3.6 ___ Python tracker <https://bugs.python.org/issue34951> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue34252] Bunch of path leaks on Python 3.7 on Release
Alberto added the comment: In Visual Studio /FP should be removed: In C/C++ → Advanced → Use Full Paths: No But still for some weird reason there is one path that gets leaked: c:\users\mysupersecretuser\downloads\python-3.7.0_\modules\_decimal\libmpdec\typearith.h In the project from where I'm using python I already removed /FP so even if it is a header it should not be showing the full path AFAIK. Any idea? -- ___ Python tracker <https://bugs.python.org/issue34252> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue34252] Bunch of path leaks on Python 3.7 on Release
New submission from Alberto : I've downloaded and compiled from sources Python 3.7 in windows. The compilation process goes great but there are a lot of paths (using __FILE__ in the source) that gets leaked in the Release version and that should not happen. This is because __FILE__ is used outside of assert or DEBUG ifdefs which should be avoided. Here is the list I've got after doing a strings on a build release: c:\users\mysupersecretuser\downloads\python-3.7.0_\objects\typeobject.c c:\users\mysupersecretuser\downloads\python-3.7.0_\python\import.c c:\users\mysupersecretuser\downloads\python-3.7.0_\objects\moduleobject.c c:\users\mysupersecretuser\downloads\python-3.7.0_\objects\longobject.c c:\users\mysupersecretuser\downloads\python-3.7.0_\python\getargs.c c:\users\mysupersecretuser\downloads\python-3.7.0_\objects\frameobject.c c:\users\mysupersecretuser\downloads\python-3.7.0_\modules\gcmodule.c c:\users\mysupersecretuser\downloads\python-3.7.0_\objects\object.c c:\users\mysupersecretuser\downloads\python-3.7.0_\objects\listobject.c c:\users\mysupersecretuser\downloads\python-3.7.0_\objects\fileobject.c c:\users\mysupersecretuser\downloads\python-3.7.0_\objects\dictobject.c c:\users\mysupersecretuser\downloads\python-3.7.0_\python\traceback.c c:\users\mysupersecretuser\downloads\python-3.7.0_\objects\tupleobject.c c:\users\mysupersecretuser\downloads\python-3.7.0_\objects\classobject.c c:\users\mysupersecretuser\downloads\python-3.7.0_\objects\unicodeobject.c c:\users\mysupersecretuser\downloads\python-3.7.0_\objects\bytearrayobject.c c:\users\mysupersecretuser\downloads\python-3.7.0_\objects\setobject.c c:\users\mysupersecretuser\downloads\python-3.7.0_\objects\bytesobject.c c:\users\mysupersecretuser\downloads\python-3.7.0_\objects\weakrefobject.c c:\users\mysupersecretuser\downloads\python-3.7.0_\objects\cellobject.c c:\users\mysupersecretuser\downloads\python-3.7.0_\objects\iterobject.c c:\users\mysupersecretuser\downloads\python-3.7.0_\objects\codeobject.c c:\users\mysupersecretuser\downloads\python-3.7.0_\python\ast.c c:\users\mysupersecretuser\downloads\python-3.7.0_\python\pystrtod.c c:\users\mysupersecretuser\downloads\python-3.7.0_\modules\_asynciomodule.c c:\users\mysupersecretuser\downloads\python-3.7.0_\modules\arraymodule.c c:\users\mysupersecretuser\downloads\python-3.7.0_\modules\_sha3\sha3module.c c:\users\mysupersecretuser\downloads\python-3.7.0_\modules\parsermodule.c c:\users\mysupersecretuser\downloads\python-3.7.0_\modules\zipimport.c FFI_TRAMPOLINE_SIZE too small in c:\users\mysupersecretuser\downloads\python-3.7.0_\modules\_ctypes\libffi_msvc\ffi.c c:\users\mysupersecretuser\downloads\python-3.7.0_\modules\_decimal\libmpdec\typearith.h c:\users\mysupersecretuser\downloads\python-3.7.0_\modules\_decimal\libmpdec\mpdecimal.c c:\users\mysupersecretuser\downloads\python-3.7.0_\modules\_decimal\libmpdec\context.c c:\users\mysupersecretuser\downloads\python-3.7.0_\modules\_ssl.c c:\users\mysupersecretuser\downloads\python-3.7.0_\modules\pyexpat.c -- components: Build messages: 322512 nosy: illera88 priority: normal severity: normal status: open title: Bunch of path leaks on Python 3.7 on Release type: enhancement versions: Python 3.7 ___ Python tracker <https://bugs.python.org/issue34252> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue34057] Py_Initialize aborts when using static Python version. Windows
Alberto added the comment: Hey Victor, I've spent another number of hours debugging the problem and trying to avoid encodings to be loaded but I've had no luck since initfsencoding is necesary for init_sys_streams to work and that's an important function that sets stdin, stout and sterr. It seems that encodings is the only thing that prevents Py_Initialize to be called and therefore for a static python version to be used. Is there any way to move encodings to pythoncore? Is there any other solution? I'm happy to put my time on this (I've already spent 3 full days debugging the problem). I think this could be considered a bug since there is no point on statically build python and use it as a library as the README stands if there is still requirements on encodings which need to reside on the filesystem. Thank you again for your time -- ___ Python tracker <https://bugs.python.org/issue34057> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue34057] Py_Initialize aborts when using static Python version. Windows
Alberto added the comment: Hi, First of all thank you for your answer. If every module can't be statically compiled within a library, what is the point of having instructions to compile python statically in the build instructions? Can I modify the code to make it completely statically? Thank you On Fri, Jul 6, 2018 at 12:27 AM STINNER Victor wrote: > > STINNER Victor added the comment: > > > Why is Python looking for external modules when it is a statically > linked library and encodings should be built-in? > > Hi, this is not a bug. Python needs its standard library. You might want > to put the whole stdlib into a single ZIP, but I don't recall how to do > that. > > The encodings and codecs modules are not built-in, but _codecs is built-in: > > >>> import encodings, codecs, _codecs > >>> encodings > > >>> codecs > > >>> _codecs > > > I suggest to close this issue as "not a bug". You should ask on a Python > mailing list or forum to get help how to build a standalone Python. > > -- > > _______ > Python tracker > <https://bugs.python.org/issue34057> > ___ > -- Alberto García Illera GPG Public Key: https://goo.gl/twKUUv -- ___ Python tracker <https://bugs.python.org/issue34057> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue34057] Py_Initialize aborts when using static Python version. Windows
New submission from Alberto : Hi, I've followed the build instructions to get a statically linked Python library in windows. The compilation works great and I get a big fat statically linked .lib file. When I use it and in my code I call Py_Initialize() the program aborts and I get this error: Fatal Python error: initfsencoding: unable to load the file system codec ModuleNotFoundError: No module named 'encodings' It seems that python is looking for encodings on the file system instead of looking for the built-in one since if I do Py_SetPythonHome(L"C:\\Python37.0-x64"); before calling Py_Initialize it works fine. Why is Python looking for external modules when it is a statically linked library and encodings should be built-in? How can I indicate Python to look for the modules in itself and not externally? Regards -- components: Interpreter Core messages: 321140 nosy: illera88 priority: normal severity: normal status: open title: Py_Initialize aborts when using static Python version. Windows type: crash versions: Python 3.8 ___ Python tracker <https://bugs.python.org/issue34057> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
ANN: JavaScripthon 0.9 has been released
I'm pleased to announce the release of version 0.9 of JavaScripthon! JavaScripthon in a small and unobtrusive yet powerful Python-to-JavaScript compiler for Python 3.5+ that targets ES6+ syntax. Changes since the previous version: - add a --source-name options to be used together with --inline-map when using -s; - move main repository to gitlab.com/metapensiero; - add support for default export and import; - add documentation for the JS() marker function; - refactor of the JS AST nodes; - fix path splitting and joining on Windows (thanks to Roman Yakubuk); There are some new contributions in this release: - BrainBacon has made a JavaScripthon loader for WebPack; - icarito has contributed support for JavaScripthon to the python-webpack-loader for WebPack; - icarito has also integrated JavaScripthon with Nuxt.js and Vue.js; - chfw has integrated JavaScripthon into pyecharts to allow Python function translation. For more informations se the project homepage at https://gitlab.com/metapensiero/metapensiero.pj It's also mirrored on github at https://github.com/metapensiero/metapensiero.pj License: GPL3 -- Alberto Berti (alberto at metapensiero.it) "gutta cavat lapidem" -- https://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
[issue28718] '*' matches entire path in fnmatch
Alberto Galera <galerajime...@gmail.com> added the comment: I see that they have commented on the lib that I made a few years ago (python-wildcard). The reason for the creation of that little fork started in this issue: https://bugs.python.org/issue25734 -- nosy: +Alberto Galera ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue28718> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: A use-case for for...else with no break
> "Wolfgang" == Wolfgang Maier> writes: Wolfgang> Try running it interactively and you'll see, Wolfgang> wolfgang I've tried but my muscolar memory failed me... i've issued a C-c C-c that usually would have sent the region of text to the interpreter session (when done from python-mode opened files in emacs) but instead i was in gnus and it sent the half prepared email :-) -- https://mail.python.org/mailman/listinfo/python-list
Re: A use-case for for...else with no break
> "Steve" == Steve D'Apranowrites: py> for x in "abcdefgh": Steve> ... print(x, end='') Steve> ... py> efghpy> Steve> "For ... else" to the rescue! py> for char in "abcdefgh": Steve> ... print(char, end='') Steve> ... else: Steve> ... print() Steve> ... Steve> abcdefgh py> else doesn't seem to bring any advantage over: for char in "abcdefgh": print(char, end='') print() -- https://mail.python.org/mailman/listinfo/python-list
Re: Invoking return through a function?
On 10/31/2017 11:01 AM, Rhodri James wrote: On 31/10/17 02:06, Alberto Riva wrote: Steve D'Aprano gave you a pretty full answer, I just wanted to add: The kind of statement I was trying to add would at least have made that explicit: return-if-so-and-so-happens. That's only obvious in the function that's doing the returning. The function that's doing the calling that gets its expectation of flow control broken has no clue, and that's my problem. Sorry, I wasn't clear: I meant that the function that's doing the returning should be called "return-if-so-and-so-happens", literally ;) So when it appears in the body of another function, it's clear that it *may* invoke a return. Not saying it's a good idea, but just that when you read something like that you can expect evaluation flow to be disrupted. Again: I'm not saying it's a good idea, please don't take this as a serious feature request :) Alberto -- E-mail address: ((lambda (s a b c) (map 'string #'code-char (mapcar (lambda (v) (setq s (+ a (mod (+ s v (- a)) b (map 'list (lambda (v) (- (char-code v) c)) " 1`-THUZ&+Wh1" 97 46 73 32) -- https://mail.python.org/mailman/listinfo/python-list
Re: Cooperative class tree filtering
Thanks Ian, >>>>> "Ian" == Ian Kelly <ian.g.ke...@gmail.com> writes: Ian> On Thu, Oct 12, 2017 at 5:07 PM, Alberto Berti <albe...@metapensiero.it> wrote: Ian> My initial reaction is: is this really worth it? This seems like an Ian> awful lot of code and added complexity in order to do away with two Ian> lines. It's a lot easier to reason about "return Ian> super().filter(element)" and verify that it does the right thing than Ian> for the complicated descriptor above. yes this was also my conclusion, that descriptor is sitting on a branch of its own and I've yet to decide on it. The fact is that i've many cases where I need a coperative superclass-subclass method execution and I was trying to find some other pattern that would fit in ;-) -- https://mail.python.org/mailman/listinfo/python-list
Re: Invoking return through a function?
>>>>> "Lele" == Lele Gaifax <l...@metapensiero.it> writes: Lele> r...@zedat.fu-berlin.de (Stefan Ram) writes: Stefan> There are many macro processors available, like the C macro Stefan> preprocessor, gpp, M4, or funnelweb. You can always use them Stefan> for your Python source (which, in this case, isn't exactly Python Stefan> source anymore). Lele> Even more to the point, MacroPy! See https://github.com/azazel75/macropy for a Lele> 3.5+ version. I share the opinion of Stefan and others, it's a bad practice. But just to have some fun I implemented it with MacroPy... This is the module with the test code:: # test.py from test_macros import macros, check_macro def checkKey(k, m): return k in m @check_macro def test(): m = {1: 'a', 2: 'b'} print('before') checkKey(3, m) print('after') here the test function is wrapped by the macro, that is defined as: # test_macros.py from macropy.core.macros import Macros from macropy.core.quotes import macros, q, u, ast_literal from macropy.core.walkers import Walker from macropy.experimental.pattern import macros, switch, _matching, ClassMatcher from ast import Call, Name, Expr macros = Macros() @macros.decorator def check_macro(tree, **kw): @Walker def transform_checkKey(tree, stop, **kw): with switch(tree): if Expr(value=Call(func=Name(id='checkKey'))): with q as result: if not ast_literal[tree.value]: print('exiting!') return stop() else: result = tree return result return transform_checkKey.recurse(tree) The macro is run with all the decorated code of the ``test()`` method passed as the ``tree`` parameter in the form of ast tree. A tree walker is then run to navigate the tree and augment the occurrence of checkKey with the conditional return And finally, a ``main`` module is needed to activate macro parsing and substitution: # test_main.py import macropy.activate import test test.test() cheers, Alberto -- https://mail.python.org/mailman/listinfo/python-list
Re: Invoking return through a function?
On 10/30/2017 12:23 AM, Rustom Mody wrote: On Sunday, October 29, 2017 at 9:52:01 PM UTC+5:30, Rick Johnson wrote: On Sunday, October 29, 2017 at 9:19:03 AM UTC-5, Alberto Riva wrote: In a language like Lisp Python is nothing like Lisp, and for good reason! Sure, we have a few lispers and functional fanboys who hang around here, and sometimes Rustom can get a little preachy about FP, but mostly, we tolerate the fanboyism -- so long as it's not rabid fanboyism. Rick's personal comments are one of the standard entertainments of this list. Enjoy! The comments on FP are more problematic: - These misconceptions are more widespread than just Rick - They are right enough to be hard to refute - And wrong enough to cause confusion and misdirection - And irrelevant to (threads like) this one My super-short rejoiner to the FP-irrelevancy is: «If there is one key takeaway from functional programming maybe it should be: "Truth is a function of time" » In more detail: - Lisp (1960) was the second functional language; its predecessor was something called Formula Translator — usually shortened to Fortran (c. 1957) - By the late 80s, many FPers had begun regard Lisp as a setback for functional programming. [Dont get me wrong: Ive enjoyed Scheme more than any other programming language. Its just that conflating Lisp and FP is an error (in 2017)] More historical details at http://blog.languager.org/2015/04/cs-history-1.html and sequel At a more conceptual level, people dont get that there are two dimensions - the apply-lambda axis — usually called functional programming - the eval-quote axis — which has precious little to do with FP (and is more relevant to your question) These two dimensions of power uniquely coincide in Lisp (Scheme). As you correctly (almost) point out - Python is very much a lisp… its semantic under-belly - However, syntactically its more like C/Java etc in the sense of having a rigid fixed-at-language-design-time syntax More at http://blog.languager.org/2013/08/applying-si-on-sicp.html For a question like macros (syntax-extensions) that sits between the two your question is interesting and I am not sure I know how to do it… I remember seeing something about this recently but my google-foo is failing me at the moment However I would look at - PEP 263 https://www.python.org/dev/peps/pep-0263/ — Source Code Encodings… - Hooking into the codec module https://docs.python.org/3/library/codecs.html - hooking into ast module https://docs.python.org/3/library/ast.html An old attempt in this direction: http://code.activestate.com/recipes/546539/ You've already got the moral-hi-horse guys giving you the dope of why this is evil. Swallow if you like. My own lightweight suggestion would be that the natural pythonic way of unstructured exit is exceptions. Not as succinct as a tailormade syntax extension. But good enough IMHO PS I personally would be interested if you get this (syntax extension) running Thanks for the interesting reply! But once again: I was not proposing to add lisp-style macros to Python; I have no interest in doing that since I believe it's pretty much impossible :) Thanks! Alberto -- E-mail address: ((lambda (s a b c) (map 'string #'code-char (mapcar (lambda (v) (setq s (+ a (mod (+ s v (- a)) b (map 'list (lambda (v) (- (char-code v) c)) " 1`-THUZ&+Wh1" 97 46 73 32) -- https://mail.python.org/mailman/listinfo/python-list
Re: Invoking return through a function?
On 10/30/2017 10:27 AM, Rhodri James wrote: On 29/10/17 16:45, Alberto Riva wrote: On 10/29/2017 11:13 AM, bartc wrote: (What the OP wants was also proposed a few weeks back in comp.lang.c. But that was only within nested functions, so if H is inside G, and G is inside F, then a 'returnall' from H would return directly directly from F. Apparently Lisp allows this...) Well, not directly, but it can be simulated with the condition system (equivalent to try/except) or with throw/catch, which is similar but doesn't use exceptions. But my point was that in Lisp you don't need to do this, because you can write a macro that expands into a return *in place*, without calling a separate function, and this eliminates the problem entirely. Since Python doesn't have macros I was looking for the next-best solution, but there doesn't seem to be one. Oh, well... You can do the same in C. I've had the displeasure of trying to maintain such code. It was near-unreadable, because it constantly broke your expectations of what the code flow *could* be. The fact that something that could return from the middle of your function without the slightest indication was a rich source of bugs. Just curious: how is this different from calling a function that throws an exception (that may or may not be caught by some other function higher up in the call stack)? That also breaks your expectations of what the code flow would be... To clarify, I agree with your concern. What I mean is that even in normal conditions there's never any guarantee that the code flow is what you expect it to be just by reading the body of a function. The kind of statement I was trying to add would at least have made that explicit: return-if-so-and-so-happens. Alberto -- E-mail address: ((lambda (s a b c) (map 'string #'code-char (mapcar (lambda (v) (setq s (+ a (mod (+ s v (- a)) b (map 'list (lambda (v) (- (char-code v) c)) " 1`-THUZ&+Wh1" 97 46 73 32) -- https://mail.python.org/mailman/listinfo/python-list
Re: Invoking return through a function?
As suggested by Ned I'm going to stop replying after pointing out just a couple of things. The most important one is the following: > But since your assertion of: "Python, like Lisp, has X,Y and > Z features in common" and furthermore that: "I cannot find > another language that has exactly these X, Y and Z > features", was used by you as a justification for this > feature request. I was not requesting any feature. I was just asking this group (that I assume includes people who are more experienced in Python than I am) if there was a way of doing something using the tools currently provided by Python. That was all. Then I mentioned the fact that I'm used to a language in which this "something" is not necessary because you can get the same effect in a cleaner and more readable way using macros, but I was absolutely NOT advocating for the addition of Lisp-like macros to Lisp. I know perfectly well that it would be impossible, because they can only work in a language that has Lisp-like syntax (which, incidentally, I find much easier to read than Java syntax, for example; these things are highly subjective). And indeed, the fact that you thought I was asking for this shows that you don't really know what Lisp macros are, otherwise you would know that they're impossible to reproduce in Python. So I apologize for any misunderstandings; I was not trying to sell anything to anyone, least of all vacuum cleaners. I was just asking for information. Thanks, Alberto On 10/29/2017 04:35 PM, Rick Johnson wrote: Alberto Riva wrote: Rick Johnson wrote: Alberto Riva wrote: Rick Johnson wrote: Alberto Riva wrote: [...] In a language like Lisp Python is nothing like Lisp, and for good reason! I would disagree with this. Actually, it's the most Lisp- like language I've encountered in my 25 years of writing software. Really? I'm sorry that you have only encountered a few "academic languages". Do some googling, there are literally thousands of them in the wilds. I'm sorry, I'm not sure I understand what you mean. I've been exposed to quite a few programming languages over the years, and my personal assessment (based on the features I consider important from my own personal point of view) is that Python is the closest to Lisp of the ones that I would consider using. It's definitely closer to Lisp than C, or Java, wouldn't you agree? It depends on what metrics you use. Once you remove all the type declarations from C and Java source, all three look very similar, with Python being the "cleanest" syntax of all. OTOH, when i look at Lisp, all i see is a language that was designed for easy machine parsing, not for the human. But that's just a syntactical comparison. Digging deeper, Python and Java are both strongly typed. And with Python's multi-paradigm nature, it is both equally useful in OOP (aka: Java) or imperative (aka: C) style. Aside from static type checking and some low level distractions, Python is very much like both of these languages. In fact, i was familiar with both Java and C before i ever became aware of Python. And the transition felt very natural to me. I don't see where you get the idea that I was only exposed to "academic languages". Just a lucky guess, i suppose. It has closures, functions are first-class objects, it's interactive, highly reflective, variables are not strongly typed... Congratulations. You've just described Ruby. And an apple- cart full of other languages as well. OK, so? Does that invalidate my statement? And even if it did, that has almost nothing to do with my original question. But since your assertion of: "Python, like Lisp, has X,Y and Z features in common" and furthermore that: "I cannot find another language that has exactly these X, Y and Z features", was used by you as a justification for this feature request. That's why i had to attack it. Because it was false. I don't consider myself a fanboy - I've used Lisp for most of my career, and now I happily use Python for 80% of what I do, even if it means putting up with the occasional limitation, as in this case. (not that i'm defending Python here...) but how do you know that this so-called missing "feature" is a limitation? Because (again in my own personal opinion) Lisp macros are wonderful, they increase programmer productivity enormously, and not having them when I'm programming in other languages is a limitation from my point of view, since I enjoy using them so much. Well, i can understand your enthusiasm, i myself become highly animated about certain topics (just ask my CO-EDs!). But you also need to understand that i am person of _reasoned_ principles. And i try not to violate my principles just because some random peddler shows-up one day on my front porch with a slick sales pitch for the next generation of vacuum cleaners. My vacuum cleaner works just fin
Re: Invoking return through a function?
On 10/29/2017 02:13 PM, Rick Johnson wrote: Alberto Riva wrote: Rick Johnson wrote: Alberto Riva wrote: [...] In a language like Lisp Python is nothing like Lisp, and for good reason! I would disagree with this. Actually, it's the most Lisp- like language I've encountered in my 25 years of writing software. Really? I'm sorry that you have only encountered a few "academic languages". Do some googling, there are literally thousands of them in the wilds. I'm sorry, I'm not sure I understand what you mean. I've been exposed to quite a few programming languages over the years, and my personal assessment (based on the features I consider important from my own personal point of view) is that Python is the closest to Lisp of the ones that I would consider using. It's definitely closer to Lisp than C, or Java, wouldn't you agree? I don't see where you get the idea that I was only exposed to "academic languages". It has closures, functions are first-class objects, it's interactive, highly reflective, variables are not strongly typed... Congratulations. You've just described Ruby. And an apple- cart full of other languages as well. OK, so? Does that invalidate my statement? And even if it did, that has almost nothing to do with my original question. I don't consider myself a fanboy - I've used Lisp for most of my career, and now I happily use Python for 80% of what I do, even if it means putting up with the occasional limitation, as in this case. (not that i'm defending Python here...) but how do you know that this so-called missing "feature" is a limitation? Because (again in my own personal opinion) Lisp macros are wonderful, they increase programmer productivity enormously, and not having them when I'm programming in other languages is a limitation from my point of view, since I enjoy using them so much. How many other languages use this "feature"? Almost none, unfortunately. So? And how many programmers swear they could not live without it? We need stats; hyperlinks; and eye witness testimonials. Heck, even a random YouTube vid would be helpful. I don't see why. I'm just talking about something that I personally feel the need for, I'm not trying to convert anyone. Why "thankfully"? Having macros in Python would be great. Of course it's not possible because of the syntax, but it would be great nevertheless :) To me, macros would seem to violate Python's "explicit is better than implicit" philosophy. But that's exactly why I would like to be able to use macros. I think that being able to write "return if this happens" is much more explicit than having to write the full if statement, every time. The idea is that you abstract a pattern giving it a name, so every time you see that name you know immediately what's going to happen, without having to decode the conditional in your mind. Possibly. But you've already poo-pooed the easy and obvious solution of using conditional logic. Not really. It's obvious that I'm going to use a conditional, I was just asking for a way to avoid having to type the same conditional over and over. Computers are meant to do work for you, after all, aren't they? :) A reasonable argument, i admit. But again, here in the peaceful fields of "Pythonia", most of us feel that "explicit is better than implicit". And why? Well, because code is read more often than it is written, and as such, explicit code will be of enormous help during the debugging process. Sure, you may save yourself a few key-strokes with features like macros, but at what cost? No action is without consequences, dontchaknow? I agree completely. Maybe we're using two different definitions of the word macro (I'm not sure how familiar you are with Lisp macros), but in my view their biggest advantage is that they make the code more readable and more explicit. And the issue of debugging is an orthogonal one, good development environments allow you to work on the original and the macro-expanded code equally easily. Alberto -- E-mail address: ((lambda (s a b c) (map 'string #'code-char (mapcar (lambda (v) (setq s (+ a (mod (+ s v (- a)) b (map 'list (lambda (v) (- (char-code v) c)) " 1`-THUZ&+Wh1" 97 46 73 32) -- https://mail.python.org/mailman/listinfo/python-list
Re: Invoking return through a function?
On 10/29/2017 12:21 PM, Rick Johnson wrote: On Sunday, October 29, 2017 at 9:19:03 AM UTC-5, Alberto Riva wrote: Hello, I'm wondering if there is a way of writing a function that causes a return from the function that called it. To explain with an example, let's say that I want to exit my function if a dict does not contain a given key. I could write: def testFun(): ... if key not in dict: return ... But if this is a test I need to do a lot of times, I'd like to replace it with something shorter and more explicit: def testFun(): ... checkKey(dict, key) ... and I'd like checkKey to cause a return *from testFun*. But under what exact _circumstances_? So, you'd like a call to `checkKey(...)` to cause a return in `testFunc` when: (1) the key exists? (2) the key doesn't exist? (3) the dict is actually a list? (3) The call raises an exception? (4) a seg fault occurs? (5) GvR regains his sanity, self-respect and dignity by 86'ing type-hints? In this specific case, I wanted to invoke a return if the key doesn't exist (as I wrote in my post). But this is not strictly relevant, my question was more general. To phrase it in yet another way: is there *any other way* to invoke return on a function, except by explicitly writing "return" in its body? Be more specific please. And _always_ refer to a named function by _name_. Never use random or implicit aliases (aka: "the function", "my function", etc...) in your prose. Both functions *ARE* functions, dontchaknow? I do, but apparently everybody else was able to understand what I was asking... :) In a language like Lisp Python is nothing like Lisp, and for good reason! I would disagree with this. Actually, it's the most Lisp-like language I've encountered in my 25 years of writing software. It has closures, functions are first-class objects, it's interactive, highly reflective, variables are not strongly typed... The only big thing missing is macros, which are a direct result of the code-is-data feature of Lisp. Sure, we have a few lispers and functional fanboys who hang around here, and sometimes Rustom can get a little preachy about FP, but mostly, we tolerate the fanboyism -- so long as it's not rabid fanboyism. I don't consider myself a fanboy - I've used Lisp for most of my career, and now I happily use Python for 80% of what I do, even if it means putting up with the occasional limitation, as in this case. this would be accomplished by defining checkKey as a macro that expands into the code shown in my first example, so that the return would be inside testFun and not insted checkKey. Is there a way of doing something like this in Python? Thankfully, no. Why "thankfully"? Having macros in Python would be great. Of course it's not possible because of the syntax, but it would be great nevertheless :) Another way of phrasing my question is: is there a way to cause a return from a function that is higher up in the call stack, rather than the currently active one, without using try/except? Possibly. But you've already poo-pooed the easy and obvious solution of using conditional logic. Not really. It's obvious that I'm going to use a conditional, I was just asking for a way to avoid having to type the same conditional over and over. Computers are meant to do work for you, after all, aren't they? :) Alberto -- E-mail address: ((lambda (s a b c) (map 'string #'code-char (mapcar (lambda (v) (setq s (+ a (mod (+ s v (- a)) b (map 'list (lambda (v) (- (char-code v) c)) " 1`-THUZ&+Wh1" 97 46 73 32) -- https://mail.python.org/mailman/listinfo/python-list
Re: Invoking return through a function?
On 10/29/2017 11:13 AM, bartc wrote: (What the OP wants was also proposed a few weeks back in comp.lang.c. But that was only within nested functions, so if H is inside G, and G is inside F, then a 'returnall' from H would return directly directly from F. Apparently Lisp allows this...) Well, not directly, but it can be simulated with the condition system (equivalent to try/except) or with throw/catch, which is similar but doesn't use exceptions. But my point was that in Lisp you don't need to do this, because you can write a macro that expands into a return *in place*, without calling a separate function, and this eliminates the problem entirely. Since Python doesn't have macros I was looking for the next-best solution, but there doesn't seem to be one. Oh, well... Thanks, Alberto -- E-mail address: ((lambda (s a b c) (map 'string #'code-char (mapcar (lambda (v) (setq s (+ a (mod (+ s v (- a)) b (map 'list (lambda (v) (- (char-code v) c)) " 1`-THUZ&+Wh1" 97 46 73 32) -- https://mail.python.org/mailman/listinfo/python-list
Re: Invoking return through a function?
On 10/29/2017 10:35 AM, Steve D'Aprano wrote: On Mon, 30 Oct 2017 01:18 am, Alberto Riva wrote: Hello, I'm wondering if there is a way of writing a function that causes a return from the function that called it. To explain with an example, let's say that I want to exit my function if a dict does not contain a given key. I could write: def testFun(): ... if key not in dict: return ... But if this is a test I need to do a lot of times, I'd like to replace it with something shorter and more explicit: def testFun(): ... checkKey(dict, key) ... You mean *less* explicit. "checkKey" gives absolutely no hint that it causes the current function to return. That's just because I used a name that was too generic in my example. I can call it "returnIfKeyMissing", and then it would be clear. and I'd like checkKey to cause a return *from testFun*. In a language like Lisp this would be accomplished by defining checkKey as a macro that expands into the code shown in my first example, so that the return would be inside testFun and not insted checkKey. Is there a way of doing something like this in Python? Fortunately not. Another way of phrasing my question is: is there a way to cause a return from a function that is higher up in the call stack, rather than the currently active one, without using try/except? No. You really should re-think your strategy. Your suggestion, if possible, would lead to difficult to maintain code where you couldn't easily tell where the exit points of a function where. But again, it's just a naming problem. Something like returnIfKeyMissing would make it easy to tell where the exit points are. And as Bartc pointed out, we already have this situation with exceptions, so it would be nothing new. Indeed, what I'm asking for could be accomplished by wrapping the body of each function in a try/catch block for an ad-hoc exception type. But again, since the language doesn't have macros, this would have to be done manually in each function. I was just asking for a more convenient way to do it, being a lazy programmer :) Imagine reading code like: def foo(x): a = sin(x) b = cos(x) print(a, b) return a + b There's one return, right? No. If Python could do what you are asking for, *every function call* could be a hidden, secret return. What a nightmare that would be. It is bad enough that any function could raise an exception, but at least exceptions halt the normal execution of code (unless explicitly caught). They don't silently continue normal execution. See above :) Thanks, Alberto -- E-mail address: ((lambda (s a b c) (map 'string #'code-char (mapcar (lambda (v) (setq s (+ a (mod (+ s v (- a)) b (map 'list (lambda (v) (- (char-code v) c)) " 1`-THUZ&+Wh1" 97 46 73 32) -- https://mail.python.org/mailman/listinfo/python-list
Invoking return through a function?
Hello, I'm wondering if there is a way of writing a function that causes a return from the function that called it. To explain with an example, let's say that I want to exit my function if a dict does not contain a given key. I could write: def testFun(): ... if key not in dict: return ... But if this is a test I need to do a lot of times, I'd like to replace it with something shorter and more explicit: def testFun(): ... checkKey(dict, key) ... and I'd like checkKey to cause a return *from testFun*. In a language like Lisp this would be accomplished by defining checkKey as a macro that expands into the code shown in my first example, so that the return would be inside testFun and not insted checkKey. Is there a way of doing something like this in Python? Another way of phrasing my question is: is there a way to cause a return from a function that is higher up in the call stack, rather than the currently active one, without using try/except? Thanks, Alberto -- E-mail address: ((lambda (s a b c) (map 'string #'code-char (mapcar (lambda (v) (setq s (+ a (mod (+ s v (- a)) b (map 'list (lambda (v) (- (char-code v) c)) " 1`-THUZ&+Wh1" 97 46 73 32) -- https://mail.python.org/mailman/listinfo/python-list
Re: Cooperative class tree filtering
Sorry, i've made a mistake in the second C body, it's written like: >>>>> "me" == Alberto Berti <albe...@metapensiero.it> writes: me> I've tried some variants of the 'super()' trick, that sometimes seems to me> change behavior if it's written like that or like super(type(self), me> self) in no clear (to me, and I failed to find extensive doc on me> super()'s behavior) way, with things that stop working if mixins are me> involved (even if the mixins do not reimplement the methods involved me> here). Eventually i ended implementing a decorator: me> from functools import partial, wraps me> class delegate_super: me> """A method decorator that delegates part of the computation to the same me> method on the ancestor class.""" me> _name = None me> _owner = None me> def __init__(self, meth): me> self._meth = meth me> @wraps(meth) me> def wrapper(*args, **kwargs): me> return self.delegator(*args, **kwargs) me> self.wrapper = wrapper me> def __get__(self, instance, owner): me> return partial(self.wrapper, instance) me> def __set_name__(self, owner, name): me> self._owner = owner me> self._name = name me> def delegator(self, instance, *args, **kwargs): me> result = self._meth(instance, *args, **kwargs) me> if result is None: me> result = getattr(super(self._owner, instance), self._name)( me> *args, **kwargs) me> return result me> class A: me> def filter(self, element): me> # the default implementation always returns True me> return True me> class B(A): me> @delegate_super me> def filter(self, element): me> if element == 'foo': me> return True me> elif element == 'bar': me> return False me> class C(B): me> @delegate_super me> def filter(self, element): me> if element == 'bar': me> return True me> else: me> return super().filter(element) The correct version is: class C(B): @delegate_super def filter(self, element): if element == 'bar': return True -- https://mail.python.org/mailman/listinfo/python-list
Cooperative class tree filtering
decorating the methods in A subclasses to free the final developer to remember to import the decorator and apply it, just like I don't want him (probably me six months from now) to have to remember to add an `else: super()...` to its computation... Has anyone done this before and has any suggestion about a better way to do it? Am I getting it wrong? cheers, Alberto -- https://mail.python.org/mailman/listinfo/python-list
[issue31163] Return destination path in Path.rename and Path.replace
New submission from Alberto Gomez-Casado: Extracted from issue31154 Both calls lack any kind of return, which leads me to expect after a rename/replace the Path instance would be changed to the new path. This is not the case (reading the PEP I have seen Path instances are kind of immutable), after the call the Path instance keeps "pointing" to the previous (and quite likely now useless) path. Returning the new path would be a reasonable option. In any case, I think the documentation should mention this behavior explicitly. -- assignee: docs@python components: Documentation, Library (Lib) messages: 300019 nosy: Alberto Gomez-Casado, docs@python, pitrou priority: normal severity: normal status: open title: Return destination path in Path.rename and Path.replace type: enhancement versions: Python 3.6 ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue31163> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue31154] Path.replace and Path.rename naming, behavior and documentation
New submission from Alberto Gomez-Casado: I find the naming of Path.replace quite unfortunate, coming from the os.path and basestring mindset, the expectation would be that it would change some substring by another substring in the Path instance. Instead, it _moves_ the file indicated by the Path object in the file system. Most of the methods of Path have no effect in the filesystem, and we have here one with a slightly misleading name which goes and moves your files around. Practically the same operation is done with Path.rename, which is less surprising since it matches popular OS commands/UIs (ren, Rename). IMHO Path.replace should not exist as is and a keyword modifier (silent?) for Path.rename toggles between the minor behavior differences of the two. Additionally: Both calls lack any kind of return, which leads me to expect after a rename/replace the Path instance would be changed to the new path. This is not the case, after the call the Path instance keeps "pointing" to the previous (and quite likely now useless) path. Returning the new path would be another reasonable option. In any case, I think the documentation should mention this behavior explicitly. And, while we are at it, having implemented the relatively dangerous replace/rename (along with convenience shorcuts for reading, writing, opening...), why was a Path.copy not included? -- assignee: docs@python components: Documentation, Library (Lib) messages: 299976 nosy: Alberto Gomez-Casado, docs@python priority: normal severity: normal status: open title: Path.replace and Path.rename naming, behavior and documentation type: behavior versions: Python 3.6 ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue31154> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue29271] Task.current_task(None) returns unexpected result
Changes by Alberto Berti <albe...@metapensiero.it>: -- nosy: +azazel ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue29271> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue22417] PEP 476: verify HTTPS certificates by default
Carlos Alberto Lopez Perez added the comment: The python 2.7 documentation for urrlib still has a big warning notice at the top saying: """ Warning When opening HTTPS URLs, it does not attempt to validate the server certificate. Use at your own risk! """ ^^ https://docs.python.org/2/library/urllib.html I believe this is incorrect since this patch was backported to the 2.7 branch. I checked it, and it verifies SSL certs by default. I guess the documentation for urllib should be updated to remove that warning? -- nosy: +clopez ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue22417> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
ANN: JavaScrypthon 0.5, now with embedded evaluation of transpiled code
Hi all, i'm pleased to announce that JavaScripthon 0.5 has been released to PyPI. JavaScrypthon can translate a subset of Python 3.5 code to ES6 JavaScript producing beautiful and lean code, while supporting some of the latest Python features. Changelog (https://github.com/azazel75/metapensiero.pj/blob/master/CHANGES.rst): - translate ``tmpl("A string with js ${interpolation}")`` to ES6 template literals; - preliminary support to translate names like ``d_foo`` and ``dd_bar`` to ``$foo`` and ``$$bar``; - addded translation of the ``assert`` statement; - fixed a bug in ``try...except...finally`` statement when there's no ``except`` section; - added translation for ``foo is not bar`` that seems to have dedicated ast node; - if the function is defined in a method but starts with ``fn_`` do not convert it to an arrow function. Useful to *not* maintain ``this``; - added translation for ``callable`` and ``hasattr/getattr/setattr``; - updated for loops to support more than one target, so now its possible to write loops like ``for k, v in iterable(a_map):``; - updated documentation; - added a new cli option ``-s`` to translate source from the command line or the standard input; - fixed a pair of bugs on sourcemaps; - added a new cli option ``--eval`` to also evaluate the produced JavaScript using the embedded interpreter; - added a new cli option ``--dump-ast`` to print out the ast tree of the passed in string; - added sorting to the rendered snippets/decorators/assignments so that their order does not change at every ricompilation; - do not re-declare variables declare in outer scopes; - updated BabelJS to version 6.18.1; - allow to import modules with dashes inside by using dunder-inside-words notation (``foo__bar`` becomes ``foo-bar``); - reuse JavaScript interpreter context to speedup translation; - update ``in`` operator to support ES6 collections; - added support for method and class decorators; - added support for class properties and descriptors; - add ``for`` loop over JS iterables; - allow to loop over inherited properties; - fix a bug on ``type()`` translation; - support for ``range()`` steps; - add support for generator functions and ``yield`` and ``yield from`` expressions; - optionally load babel-polyfill before evaluating code; - fix a bug on sourcemaps having wrong references when there are documentation elements; - translate ``__get__()`` and ``__set__()`` to to JS equivalents; - implement ``dict(foo).update(bar)`` and ``dict(foo).copy``; - documentation improvements; -- https://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Re: Question about asyncio and blocking operations
>>>>> "Frank" == Frank Millman <fr...@chagford.com> writes: Frank> Now I have another problem. I have some classes which retrieve some Frank> data from the database during their __init__() method. I find that it Frank> is not allowed to call a coroutine from __init__(), and it is not Frank> allowed to turn __init__() into a coroutine. IMHO this is semantically correct for a method tha should really initialize that instance an await in the __init__ means having a suspension point that makes the initialization somewhat... unpredictable :-). To cover the cases when you need to call a coroutine from a non coroutine function like __init__ I have developed a small package that helps maintaining your code almost clean, where you can be sure that after some point in your code flow, the coroutines scheduled by the normal function have been executed. With that you can write code like this: from metapensiero.asyncio import transaction class MyObject(): def __init__(self): tran = transaction.get() tran.add(get_db_object('company'), cback=self._init) # get_db_object is a coroutine def _init(self, fut): self.company = fut.result() async external_coro(): # this is the calling context, which is a coro async with transction.begin(): o = MyObject # maybe other stuff # start using your db object o.company... This way the management of the "inner" coroutine is simpler, and from your code it's clear it suspends to wait and after that all the "stashed" coroutines are guaranteed to be executed. Hope it helps, Alberto -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about asyncio and blocking operations
>>>>> "Alberto" == Alberto Berti <albe...@metapensiero.it> writes: Alberto> async external_coro(): # this is the calling context, which is a coro Alberto> async with transction.begin(): Alberto> o = MyObject Alberto> # maybe other stuff ops... here it is "o = MyObject()" ;-) -- https://mail.python.org/mailman/listinfo/python-list
RE: licenses
Thank you very much for your reply. Best Regards From: Cody Piersall [mailto:cody.piers...@gmail.com] Sent: Sunday, January 10, 2016 1:43 PM To: python-list@python.org Cc: Martinez, Jorge Alberto (GE Aviation) Subject: Re: licenses On Fri, Jan 8, 2016 at 1:41 PM, Martinez, Jorge Alberto (GE Aviation) <jorgealberto.marti...@ge.com<mailto:jorgealberto.marti...@ge.com>> wrote: > > Hello > We develop applications here with Python and I want to know if there's issues > by using. > We use NumPy, PyDaqMx, Py Visa > > How can we cover this licensing? I am not a lawyer, and this is not legal advice. * NumPy is BSD-licensed, which means you can use NumPy in a commercial product as long as you include its license. * PyDAQmx is BSD-licensed as well. (You can find that information in their GitHub repository's README, https://github.com/clade/PyDAQmx<https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_clade_PyDAQmx=CwMFaQ=IV_clAzoPDE253xZdHuilRgztyh_RiV3wUrLrDQYWSI=XhZdnDxKqbMVxHnMKS8cy39qvizJj-B5o1h42ApbaXU=g9V4Hi68th5LHEdybauMHDf3-P8FxDr7KoBeaF1zDos=YFRBLoWBFEXPbaDcMCvXQXuGi1TLIcuwhwlebfvQX34=>) * Py Visa is MIT licensed (info on their GitHub: https://github.com/hgrecco/pyvisa/blob/master/LICENSE<https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_hgrecco_pyvisa_blob_master_LICENSE=CwMFaQ=IV_clAzoPDE253xZdHuilRgztyh_RiV3wUrLrDQYWSI=XhZdnDxKqbMVxHnMKS8cy39qvizJj-B5o1h42ApbaXU=g9V4Hi68th5LHEdybauMHDf3-P8FxDr7KoBeaF1zDos=RNSWKR0E0lk6NXmKDXICYkut9j3iAoAuWz8arjFMnfc=>), which means you can also use it in your software as long as you include the license. For summaries of lots of licenses, you can look at tldrlegal.com<https://urldefense.proofpoint.com/v2/url?u=http-3A__tldrlegal.com=CwMFaQ=IV_clAzoPDE253xZdHuilRgztyh_RiV3wUrLrDQYWSI=XhZdnDxKqbMVxHnMKS8cy39qvizJj-B5o1h42ApbaXU=g9V4Hi68th5LHEdybauMHDf3-P8FxDr7KoBeaF1zDos=uWyBQEUIttmuMHxJWbrWHYJYrlkGfrkd4afl-sq8cfc=>. * BSD license: https://tldrlegal.com/license/bsd-3-clause-license-(revised)<https://urldefense.proofpoint.com/v2/url?u=https-3A__tldrlegal.com_license_bsd-2D3-2Dclause-2Dlicense-2D-28revised-29=CwMFaQ=IV_clAzoPDE253xZdHuilRgztyh_RiV3wUrLrDQYWSI=XhZdnDxKqbMVxHnMKS8cy39qvizJj-B5o1h42ApbaXU=g9V4Hi68th5LHEdybauMHDf3-P8FxDr7KoBeaF1zDos=OOC2Es2Zx5J_Tz8LJCc_8IY-2ISEstA9rqrqo84669M=> * MIT license: https://tldrlegal.com/license/mit-license<https://urldefense.proofpoint.com/v2/url?u=https-3A__tldrlegal.com_license_mit-2Dlicense=CwMFaQ=IV_clAzoPDE253xZdHuilRgztyh_RiV3wUrLrDQYWSI=XhZdnDxKqbMVxHnMKS8cy39qvizJj-B5o1h42ApbaXU=g9V4Hi68th5LHEdybauMHDf3-P8FxDr7KoBeaF1zDos=fLK-HY63jkRmDV1kK3CUS4a9ljAX4NnURUFPBuIngF0=> It's never a bad idea to consult a lawyer. Since you work for GE, I would imagine there is an army of lawyers happy to answer this question at your disposal. Finding out how to talk to them might be the hard part. Cody -- https://mail.python.org/mailman/listinfo/python-list
licenses
Hello We develop applications here with Python and I want to know if there's issues by using. We use NumPy, PyDaqMx, Py Visa How can we cover this licensing? Regards Jorge Alberto Martinez GE Aviation Systems HW Team Manager GEIQ Power Engineering T +52 442 456 6446 E jorgealberto.marti...@ge.com<mailto:jorgealberto.marti...@ge.com> Calle Campo Real #1692, Residencial el Refugio, Querétaro, Qro, CP 76146 Mexico. GE Imagination at work I have Feedback for GEIQ<http://ciat.com.mx/customers/feedback> Jorge Alberto Martinez GE Aviation Systems HW Team Manager GEIQ Power Engineering T +52 442 456 6446 E jorgealberto.marti...@ge.com<mailto:jorgealberto.marti...@ge.com> Calle Campo Real #1692, Residencial el Refugio, Querétaro, Qro, CP 76146 Mexico. GE Imagination at work I have Feedback for GEIQ<http://ciat.com.mx/customers/feedback> -- https://mail.python.org/mailman/listinfo/python-list
[issue22888] ensurepip and distutils' build_scripts fails on Windows when path to Python contains accented characters
New submission from José Alberto Goncalves: Summary: Python 3.4's venv works fine in Windows, and pip works fine when installing both pure Python libraries and extension modules. However, when the virtual environment is under a path with non-ASCII characters, attempting to install a package that specifies console_scripts or scripts (like pip or mutagen, respectivelly), it fails with encoding errors. I looked around the Internet for a solution but the best I could find was Issue #10419, which is over 3 years old and is marked as resolved, and couldn't find any other open issue about this. Details of my case: I created a Python 3.4 (32-bit) virtualenv via Python Tools for Visual Studio, on windows 8.1 (64-bit), in a folder that is under my home directory (C:\Users\José Alberto\), which happens to contain an accented character, using the latest Python you can download from the homepage. Via Powershell I activated the virtualenv and tried to execute pip install mutagen (https://pypi.python.org/pypi/mutagen, it is relevant because it specifies scripts in its setup.py). The installation failed with the following error: Downloading/unpacking mutagen Running setup.py (path:C:\Users\José Alberto\Documents\podtimizer\env_podtimizer\build\mutagen\setup.py) egg_info for package mutagen Installing collected packages: mutagen Running setup.py install for mutagen Traceback (most recent call last): File C:\Python34\lib\distutils\command\build_scripts.py, line 114, in copy_scripts shebang.decode('utf-8') UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 14: invalid continuation byte During handling of the above exception, another exception occurred: Traceback (most recent call last): File string, line 1, in module File C:\Users\JosÚ Alberto\Documents\podtimizer\env_podtimizer\build\mutagen\setup.py, line 277, in module File C:\Python34\lib\distutils\core.py, line 148, in setup dist.run_commands() File C:\Python34\lib\distutils\dist.py, line 955, in run_commands self.run_command(cmd) File C:\Python34\lib\distutils\dist.py, line 974, in run_command cmd_obj.run() File C:\Users\JosÚ Alberto\Documents\podtimizer\env_podtimizer\lib\site-packages\setuptools-6.0.2-py3.4.egg\setuptools\command\install.py, line 61, in run File C:\Python34\lib\distutils\command\install.py, line 539, in run self.run_command('build') File C:\Python34\lib\distutils\cmd.py, line 313, in run_command self.distribution.run_command(command) File C:\Python34\lib\distutils\dist.py, line 974, in run_command cmd_obj.run() File C:\Python34\lib\distutils\command\build.py, line 126, in run self.run_command(cmd_name) File C:\Python34\lib\distutils\cmd.py, line 313, in run_command self.distribution.run_command(command) File C:\Python34\lib\distutils\dist.py, line 974, in run_command cmd_obj.run() File C:\Python34\lib\distutils\command\build_scripts.py, line 50, in run self.copy_scripts() File C:\Python34\lib\distutils\command\build_scripts.py, line 118, in copy_scripts from utf-8.format(shebang)) ValueError: The shebang (b'#!C:\\Users\\Jos\xe9 Alberto\\Documents\\podtimizer\\env_podtimizer\\Scripts\\python.exe\n') is not decodable from utf-8 I looked around the Internet for a solution, but the best I could find was the Issue #10419, which is over 3 years old and is marked as closed and resolved. The last comment mentions a fix that was commited to Distribute around that time, with the caveat that entry points script creation would fail if the path contained unencodeable characters (which sounds exactly like the problem I'm having). I Couldn't find an open issue to follow up on this. I went to the source of the error, around Lib/distutils/command/build_scripts.py:106. Since this is Windows, the result of os.fsencode() uses the encoding 'mbcs' (as reported by Python), then it tries to decode it back using utf-8, and it blows up: import os os.fsencode('C:\\Users\\José Alberto\\') b'C:\\Users\\Jos\xe9 Alberto\\' 'C:\\Users\\José Alberto\\'.encode('utf-8') b'C:\\Users\\Jos\xc3\xa9 Alberto\\' I commented both try..except after the os.fsencode and it worked, but commenting random code whose purpose I don't fully understand doesn't seem like a good strategy. While testing for the above, I found I couldn't finish installing pip successfully on a virtualenv using just the Python installed from python.org. On Powershell I created several virtualenvs using C:\Python34\python.exe -m venv. The envs were created successfully, but the pip's console_scripts installation failed silently. I could still run python -m pip and install packages, but the pip.exe files were not created. I removed pip from the environment's site-packages directory and tried to reinstall it via python -m ensurepip
[issue22887] ensurepip and distutils' build_scripts fails on Windows when path to Python contains accented characters
New submission from José Alberto Goncalves: Summary: Python 3.4's venv works fine in Windows, and pip works fine when installing both pure Python libraries and extension modules. However, when the virtual environment is under a path with non-ASCII characters, attempting to install a package that specifies console_scripts or scripts (like pip or mutagen, respectivelly), it fails with encoding errors. I looked around the Internet for a solution but the best I could find was Issue #10419, which is over 3 years old and is marked as resolved, and couldn't find any other open issue about this. Details of my case: I created a Python 3.4 (32-bit) virtualenv via Python Tools for Visual Studio, on windows 8.1 (64-bit), in a folder that is under my home directory (C:\Users\José Alberto\), which happens to contain an accented character, using the latest Python you can download from the homepage. Via Powershell I activated the virtualenv and tried to execute pip install mutagen (https://pypi.python.org/pypi/mutagen, it is relevant because it specifies scripts in its setup.py). The installation failed with the following error: Downloading/unpacking mutagen Running setup.py (path:C:\Users\José Alberto\Documents\podtimizer\env_podtimizer\build\mutagen\setup.py) egg_info for package mutagen Installing collected packages: mutagen Running setup.py install for mutagen Traceback (most recent call last): File C:\Python34\lib\distutils\command\build_scripts.py, line 114, in copy_scripts shebang.decode('utf-8') UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 14: invalid continuation byte During handling of the above exception, another exception occurred: Traceback (most recent call last): File string, line 1, in module File C:\Users\JosÚ Alberto\Documents\podtimizer\env_podtimizer\build\mutagen\setup.py, line 277, in module File C:\Python34\lib\distutils\core.py, line 148, in setup dist.run_commands() File C:\Python34\lib\distutils\dist.py, line 955, in run_commands self.run_command(cmd) File C:\Python34\lib\distutils\dist.py, line 974, in run_command cmd_obj.run() File C:\Users\JosÚ Alberto\Documents\podtimizer\env_podtimizer\lib\site-packages\setuptools-6.0.2-py3.4.egg\setuptools\command\install.py, line 61, in run File C:\Python34\lib\distutils\command\install.py, line 539, in run self.run_command('build') File C:\Python34\lib\distutils\cmd.py, line 313, in run_command self.distribution.run_command(command) File C:\Python34\lib\distutils\dist.py, line 974, in run_command cmd_obj.run() File C:\Python34\lib\distutils\command\build.py, line 126, in run self.run_command(cmd_name) File C:\Python34\lib\distutils\cmd.py, line 313, in run_command self.distribution.run_command(command) File C:\Python34\lib\distutils\dist.py, line 974, in run_command cmd_obj.run() File C:\Python34\lib\distutils\command\build_scripts.py, line 50, in run self.copy_scripts() File C:\Python34\lib\distutils\command\build_scripts.py, line 118, in copy_scripts from utf-8.format(shebang)) ValueError: The shebang (b'#!C:\\Users\\Jos\xe9 Alberto\\Documents\\podtimizer\\env_podtimizer\\Scripts\\python.exe\n') is not decodable from utf-8 I looked around the Internet for a solution, but the best I could find was the Issue #10419, which is over 3 years old and is marked as closed and resolved. The last comment mentions a fix that was commited to Distribute around that time, with the caveat that entry points script creation would fail if the path contained unencodeable characters (which sounds exactly like the problem I'm having). I Couldn't find an open issue to follow up on this. I went to the source of the error, around Lib/distutils/command/build_scripts.py:106. Since this is Windows, the result of os.fsencode() uses the encoding 'mbcs' (as reported by Python), then it tries to decode it back using utf-8, and it blows up: import os os.fsencode('C:\\Users\\José Alberto\\') b'C:\\Users\\Jos\xe9 Alberto\\' 'C:\\Users\\José Alberto\\'.encode('utf-8') b'C:\\Users\\Jos\xc3\xa9 Alberto\\' I commented both try..except after the os.fsencode and it worked, but commenting random code whose purpose I don't fully understand doesn't seem like a good strategy. While testing for the above, I found I couldn't finish installing pip successfully on a virtualenv using just the Python installed from python.org. On Powershell I created several virtualenvs using C:\Python34\python.exe -m venv. The envs were created successfully, but the pip's console_scripts installation failed silently. I could still run python -m pip and install packages, but the pip.exe files were not created. I removed pip from the environment's site-packages directory and tried to reinstall it via python -m ensurepip
python app hosting
Hi, I'm looking for some server to host an xmlrpc server app I've made. Can someone help me find any? VII Escuela Internacional de Verano en la UCI del 30 de junio al 11 de julio de 2014. Ver www.uci.cu -- https://mail.python.org/mailman/listinfo/python-list
Re: authentication with python-ldap
I have been doing the same thing and I tried to use java for testing the credentials and they are correct. It works perfectly with java. I really don´t know what we´re doing wrong. You are accessing a protected operation of the LDAP server and it (the server) rejects it due to invalid credentials. You may have forgotten to pass on credentials (e.g. a password) or the credentials do not fit to the specified user (maybe the user does not exist at all). http://www.uci.cu -- http://mail.python.org/mailman/listinfo/python-list
examples of pyraknet
do anyone has examples of pyraknet??? I've being seen these ones (http://nullege.com/codes/search/pyraknet) but I still don't understand lot of things about it and I can't find anything else. http://www.uci.cu -- http://mail.python.org/mailman/listinfo/python-list
A newbie question
Hi, All. I'm a (old) delphi developer. I want to learn Python. I've python 2.7 and django. For learning purpose I want to use firebird. But, package (egg) to use firebird needs easy_install for setup. When i run: python ez_setup.py install python says me error: Downloading http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-p y2.7.egg Searching for install Reading http://pypi.python.org/simple/install/ Couldn't find index page for 'install' (maybe misspelled?) Scanning index of all packages (this may take a while) Reading http://pypi.python.org/simple/ No local packages or download links found for install Best match: None Traceback (most recent call last): File ez_setup.py, line 278, in module main(sys.argv[1:]) File ez_setup.py, line 213, in main return main(list(argv)+[egg]) # we're done here File C:\Python27\Scripts\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_ install.py, line 1712, in main File C:\Python27\Scripts\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_ install.py, line 1700, in with_ei_usage File C:\Python27\Scripts\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_ install.py, line 1716, in lambda File C:\Python27\lib\distutils\core.py, line 152, in setup dist.run_commands() File C:\Python27\lib\distutils\dist.py, line 953, in run_commands self.run_command(cmd) File C:\Python27\lib\distutils\dist.py, line 972, in run_command cmd_obj.run() File C:\Python27\Scripts\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_ install.py, line 211, in run File C:\Python27\Scripts\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_ install.py, line 434, in easy_install File C:\Python27\Scripts\setuptools-0.6c11-py2.7.egg\setuptools\package_index .py, line 475, in fetch_distribution AttributeError: 'NoneType' object has no attribute 'clone' In download site I get info about installer works only on win32, but I'm uisng 64 bit version, so I need to do setup manually. Searching error, I see a lot of message baout errors AFTER easy_install was done. Also, I see that some link used in python file does'nt exist or is broken. TIA for any suggestion. A. -- http://mail.python.org/mailman/listinfo/python-list
Re: A newbie question
Hi, Colin. Thanks for your answer. But C:\Python27\Scripts is in my path and my trouble is about INSTALL easy_isntall. Bye A. -- http://mail.python.org/mailman/listinfo/python-list
pyrudp
can someone give me a link to download pyrudp. I tried here http://code.google.com/p/pyrudp/ but didn´t worked. if someone can give me another idea it will be great to. I´m traying to make a reliable udp connection help will be really appreciated -- http://mail.python.org/mailman/listinfo/python-list
Re: pyrudp
I´ve tried it but it´s not reliable. Datagrams can arive disorganised or just not arive. Some programmers said I most use TCP, but I need to use UDP. that´s why I need pyrudp, but I can not find it. On Jan 30, 2013, at 8:12 AM, Jorge Alberto Diaz Orozco What about the native socket call to SOCK_DGRAM? Here is a simple example to read messages of a udp socket. import socket UDP_IP = 127.0.0.1 UDP_PORT = 5005 sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.bind((UDP_IP, UDP_PORT)) while True: data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes print received message:, data -- http://mail.python.org/mailman/listinfo/python-list
Re: pyrudp
I want to use a reliable UDP connection like you say, a TCP like connection but over UDP. thaks for your recomendation, if I get good results I promise to share them. - Original Message - From: Michael Torrie torr...@gmail.com To: python-list@python.org Sent: Wednesday, January 30, 2013 9:16:15 AM Subject: Re: pyrudp Excuse me for chuckling, but your complaint that UDP packets can arive disorganised or just not arive describes exactly what UDP does by design! If you need to use UDP then you will have to live with this. I always consider UDP to stand for UNRELIABLE datagram packets. They can and do come in any order, or not at all. That's exactly the expected behavior of UDP. If you want to build a reliable connection on top of UDP you'll have to invent some sort of tcp-like protocol that uses UDP packets. An example of a real all that does this is openvpn. The Bell Labs Plan 9 RUDP protocol is probably what you were shooting for by trying to use the non-existent pyrudp code. But I fear you'll have to implement it yourself. pyrudp is an empty project on Google Code. The owner intended to develop some code but never did. -- http://mail.python.org/mailman/listinfo/python-list
Re: pyrudp
I have restrictions in my system that does not allow me to use TCP, so I want to make a pipe over UDP imitating TCP behavior. I have control over both endpoints, and I´m writing both of them. I just don´t want to re-invent the wheel and I´m looking for a reliable UDP sockets implementation for Python so I can start from there. _ It's nice to want but what is your actual condition/problem? Are you trying to re-invent the wheel, implement a senior project, or are you trying to work around some administrative or technical restriction against tcp? What's the use case? Do you have control over both ends? Are you writing both ends of the imitation tcp you're writing? One of the car magazines published a road test of the Mercedes GT (garbage truck). It had plenty of power, but its top speed was 6 mph, and it leaned horribly around the pylon obstacle course. Not what I'd take to the race track. Point is that a definitive specification of requirements will be much more useful than a simple wanna. -- http://mail.python.org/mailman/listinfo/python-list
python ldap bind error
hi there. I'm working with python ldap and I need to authenticate my user. this is the code I'm using. import ldap ldap.set_option(ldap.OPT_REFERRALS,0) ldap.protocol_version = 3 conn = ldap.initialize(ldap://ldap.domain.cu;) conn.simple_bind_s(u...@domain.cu,password) every time I do this it gives me the next error: ldap.INVALID_DN_SYNTAX: {'info': 'invalid DN', 'desc': 'Invalid DN syntax'} can someone help me??? I don't know what I'm doing wrong 10mo. ANIVERSARIO DE LA CREACION DE LA UNIVERSIDAD DE LAS CIENCIAS INFORMATICAS... CONECTADOS AL FUTURO, CONECTADOS A LA REVOLUCION http://www.uci.cu http://www.facebook.com/universidad.uci http://www.flickr.com/photos/universidad_uci -- http://mail.python.org/mailman/listinfo/python-list
ntlm authentication for urllib2
Hi there: I'm working with urllib2 to open some urls and grab some data. The url will be inserted by the user and my script will open it and parse the page for results. the thing is I'm behind a ntlm proxy, and I've tried with a lot of things to authenticate but it still doesn't work at all. I did some research and found pytho-ntlm but I'm not sure how to use it. I wrote something like this and it still giving me an authentication error: Can someone help me??? import urllib2 from HTTPNtlmAuthHandler import HTTPNtlmAuthHandler url = 'http://url.i.want.to.parse' user = u'DOMAIN\\myuser' password = 'mypass' passman = urllib2.HTTPPasswordMgrWithDefaultRealm() passman.add_password(None, url, user , password) auth_NTLM = HTTPNtlmAuthHandler(passman) proxy_handler = urllib2.ProxyHandler({'http': 'http://10.0.0.1:8080'}) opener = urllib2.build_opener(proxy_handler, auth_NTLM) urllib2.install_opener(opener) response = urllib2.urlopen(url) print 'done' print(response.read()) 10mo. ANIVERSARIO DE LA CREACION DE LA UNIVERSIDAD DE LAS CIENCIAS INFORMATICAS... CONECTADOS AL FUTURO, CONECTADOS A LA REVOLUCION http://www.uci.cu http://www.facebook.com/universidad.uci http://www.flickr.com/photos/universidad_uci -- http://mail.python.org/mailman/listinfo/python-list
proxy??
Hi there. Does anyone knows how to manage headers using a simple proxy??? I'm doing this but It gives me problems In some pages. import SocketServer import SimpleHTTPServer import urllib2 PORT = class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self): try: print self.path self.copyfile(urllib2.urlopen(self.path), self.wfile) except: print 'error',self.path httpd = SocketServer.ForkingTCPServer(('127.0.0.1', PORT), Proxy) print serving at port, PORT httpd.serve_forever() 10mo. ANIVERSARIO DE LA CREACION DE LA UNIVERSIDAD DE LAS CIENCIAS INFORMATICAS... CONECTADOS AL FUTURO, CONECTADOS A LA REVOLUCION http://www.uci.cu http://www.facebook.com/universidad.uci http://www.flickr.com/photos/universidad_uci -- http://mail.python.org/mailman/listinfo/python-list
Re: proxy??
When I try to open facebook or search something using google it is just not working. gives me forbidden or not found errors. that's why I think the problem is about the headers of the request. On 20/11/12 15:29, Joshua Landau wrote: On 20 November 2012 14:48, Jorge Alberto Diaz Orozco jaoro...@estudiantes.uci.cu mailto:jaoro...@estudiantes.uci.cu wrote: Hi there. Does anyone knows how to manage headers using a simple proxy??? I'm doing this but It gives me problems In some pages. I don't know the answer, but I do know you'd get more favour if you explained whatproblems and In some pages refer to. import SocketServer import SimpleHTTPServer import urllib2 PORT = class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self): try: print self.path self.copyfile(urllib2.urlopen(self.path), self.wfile) except: print 'error',self.path httpd = SocketServer.ForkingTCPServer(('127.0.0.1', PORT), Proxy) print serving at port, PORT httpd.serve_forever() 10mo. ANIVERSARIO DE LA CREACION DE LA UNIVERSIDAD DE LAS CIENCIAS INFORMATICAS... CONECTADOS AL FUTURO, CONECTADOS A LA REVOLUCION http://www.uci.cu http://www.facebook.com/universidad.uci http://www.flickr.com/photos/universidad_uci-- http://mail.python.org/mailman/listinfo/python-list
[issue15637] Segfault reading null VMA (works fine in python 2.x)
Alberto Milone added the comment: I can confirm that the suggested changes solve the problem here. Thanks everyone! -- resolution: - invalid ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15637 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue15637] Segfault reading null VMA (works fine in python 2.x)
New submission from Alberto Milone: The attached test case works fine in Python 2.7 but causes Pyhton 3.2 to segfault. -- components: ctypes files: randr_test messages: 168087 nosy: albertomilone priority: normal severity: normal status: open title: Segfault reading null VMA (works fine in python 2.x) type: crash versions: Python 3.2 Added file: http://bugs.python.org/file26782/randr_test ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15637 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue15637] Segfault reading null VMA (works fine in python 2.x)
Alberto Milone added the comment: it should just be possible to retrieve major and minor which we pass by reference to XRRQueryVersion. Without this pretty much any other call fails. Also, it works without problems with python 2.7. -- versions: -Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15637 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8739] Update to smtpd.py to RFC 5321
Alberto Trevino albe...@byu.edu added the comment: David, I'd be happy to help, but I'm pretty busy for the next month. I read the description of your patch, and it sounds good to me. Anything that moves the project forward is always welcomed. Thanks for your work on this. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8739 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Python IDE/Eclipse
I like Aptana Studio http://www.aptana.com/products/studio3 2011/8/26 Dave Boland dbola...@fastmail.fm: I'm looking for a good IDE -- easy to setup, easy to use -- for Python. Any suggestions? I use Eclipse for other projects and have no problem with using it for Python, except that I can't get PyDev to install. It takes forever, then produces an error that makes no sense. An error occurred while installing the items session context was:(profile=PlatformProfile, phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Install, operand=null -- [R]org.eclipse.cvs 1.0.400.v201002111343, action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallBundleAction). Cannot connect to keystore. This trust engine is read only. The artifact file for osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was not found. Any suggestions on getting this to work? Thanks, Dave -- http://mail.python.org/mailman/listinfo/python-list -- Atte. Moisés Alberto Lindo Gutarra Asesor - Desarrollador Java / Open Source Linux Registered User #431131 - http://counter.li.org/ Cel: (511) 995081720 - Rpm: *548913 EMail: mli...@gmail.com MSN: mli...@tumisolutions.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.2 vs Java 1.6
I work with java since 1997 and with python three years ago, and i really think that python performance is much better than java, i made same applications using both and python always responses better. Try to do the same with a little appication accesing data bases, using ftp clients, etc and you will see what i mean. 2011/4/8 km srikrishnamo...@gmail.com: Hi All, How does python 3.2 fare compared to Java 1.6 in terms of performance ? any pointers or observations ? regards, KM -- http://mail.python.org/mailman/listinfo/python-list -- Atte. Moisés Alberto Lindo Gutarra Asesor - Desarrollador Java / Open Source Linux Registered User #431131 - http://counter.li.org/ Cel: (511) 995081720 EMail: mli...@gmail.com MSN: mli...@tumisolutions.com -- http://mail.python.org/mailman/listinfo/python-list
[issue8739] Update to smtpd.py to RFC 5321
Alberto Trevino albe...@byu.edu added the comment: On Sunday, August 15, 2010 09:19:27 am Giampaolo Rodola' wrote: Patch no longer applies cleanly because smtpd.py changed in the meantime. Is someone going to fix that or I am expected to play daily catch-up until this gets merged? A further comment: -def __init__(self, server, conn, addr): +def __init__(self, server, conn, addr, size = 0): -def __init__(self, localaddr, remoteaddr): +def __init__(self, localaddr, remoteaddr, size = 0): This change breaks backward compatibility. I think it would be better to provide this as a SMTPChannel.size_limit class attribute. Unfortunately, I don't have the time in the next few weeks to make that change. Can someone else make it? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8739 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8739] Update to smtpd.py to RFC 5321
Alberto Trevino albe...@byu.edu added the comment: On Monday, August 16, 2010 11:42:51 am you wrote: Re-adapted patch including size_limit change as described in my previous message is in attachment. Barry and Alberto, could you take a final look at it before committing? Looks good to me. If the tests pass, then I'm good to go. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8739 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8739] Update to smtpd.py to RFC 5321
Alberto Trevino albe...@byu.edu added the comment: On Monday, August 16, 2010 12:58:07 pm Barry A. Warsaw wrote: The one thing that looks weird to me is VRFY. Since it never actually does verify the user, should we even claim to support the command? Why not let subclasses claim support if they want to add it? RFC 5321 section 4.5.1 states VRFY should be implemented in order to be considered an RFC 5321-compliant implementation. But, in section 3.5.3 paragraph 2 it states that if the actual verification was not performed but syntax was checked similar to RCPT, then the response code should be 252. So my purposes for providing the plumbing for VRFY are: 1. Provide a basic, valid implementation to be as RFC 5321-compliant as possible. 2. Let users know the command is there so that it can be reimplemented as they build their solutions. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8739 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8739] Update to smtpd.py to RFC 5321
Alberto Trevino albe...@byu.edu added the comment: Any more work I need to do on this patch? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8739 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9168] setuid in smtp.py sheds privileges before binding port
Alberto Trevino albe...@byu.edu added the comment: I haven't heard anything on this problem or my patch. What's the status? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9168 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8739] Update to smtpd.py to RFC 5321
Alberto Trevino albe...@byu.edu added the comment: Sorry. This is my first submission to Python, so I'm learning the process as I go. This latest patch is done against today's SVN snapshot. Just to summarize, it does the following: * Updates the main smtpd.py module to make it RFC 5321 compliant: - Adds EHLO support - Provides basic VRFY support - Updated messages (more in line with RFC 5321 examples) * Adds additional functionality to smtpd.py: - Adds HELP support - Implements DATA size limits (optional feature -- backward compatible) - 8BITMIME extension plubming * Fixes setuid bug in smtpd.py as explained in issue 9168 * Updates test-smtpd.py to test new functionality * Updates test-smtpdlib.py to work with updates to smtpd.py Again, please review and comment as necessary. -- Added file: http://bugs.python.org/file18397/smtpd.py-0.2-rfc5321-enhancements-5.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8739 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9168] setuid in smtp.py sheds privileges before binding port
Changes by Alberto Trevino albe...@byu.edu: -- type: - crash versions: +Python 3.1 -Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9168 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8739] Update to smtpd.py to RFC 5321
Alberto Trevino albe...@byu.edu added the comment: On Monday, July 05, 2010 10:41:28 am you wrote: Yes, the fact that there are no unit tests for the new functionality. Sorry to take so long to reply. I have attached the latest version of the patch which does everything in rev. 2 of the patch, patches the setuid problem discussed in issue 9168, updates to the unit test to account for the changes and to test the new functionality, plus some little changes here and there. Please review and advise. -- Added file: http://bugs.python.org/file18332/smtpd.py-0.2-rfc5321-enhancements-4.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8739 ___diff -aur Python-3.1.2.orig/Lib/smtpd.py Python-3.1.2/Lib/smtpd.py --- Python-3.1.2.orig/Lib/smtpd.py 2009-02-21 13:59:32.0 -0700 +++ Python-3.1.2/Lib/smtpd.py 2010-08-02 08:23:04.424066197 -0600 @@ -1,5 +1,5 @@ #! /usr/bin/env python -An RFC 2821 smtp proxy. +An RFC 5321 smtp proxy. Usage: %(program)s [options] [localhost:localport [remotehost:remoteport]] @@ -20,6 +20,11 @@ Use `classname' as the concrete SMTP proxy class. Uses `PureProxy' by default. +--size limit +-s limit +Restrict the total size of the incoming message to limit number of +bytes. Defaults to 0 (no limit). + --debug -d Turn on debugging prints. @@ -35,10 +40,9 @@ and if remoteport is not given, then 25 is used. - # Overview: # -# This file implements the minimal SMTP protocol as defined in RFC 821. It +# This file implements the minimal SMTP protocol as defined in RFC 5321. It # has a hierarchy of classes which implement the backend functionality for the # smtpd. A number of classes are provided: # @@ -59,15 +63,18 @@ # gets forwarded to a real backend smtpd, as with PureProxy. Again, errors # are not handled correctly yet. # -# Please note that this script requires Python 2.0 +# Please note that this script requires Python 3.0 # # Author: Barry Warsaw ba...@python.org # +# Contributors: +# Alberto Trevino albe...@byu.edu +# # TODO: # # - support mailbox delivery # - alias files -# - ESMTP +# - Handle more ESMTP extensions # - handle error codes from the backend smtpd import sys @@ -82,7 +89,7 @@ __all__ = [SMTPServer,DebuggingServer,PureProxy,MailmanProxy] program = sys.argv[0] -__version__ = 'Python SMTP proxy version 0.2' +__version__ = 'Python SMTP proxy version 0.21' class Devnull: @@ -96,7 +103,6 @@ COMMASPACE = ', ' - def usage(code, msg=''): print(__doc__ % globals(), file=sys.stderr) if msg: @@ -104,16 +110,16 @@ sys.exit(code) - class SMTPChannel(asynchat.async_chat): COMMAND = 0 DATA = 1 -def __init__(self, server, conn, addr): +def __init__(self, server, conn, addr, size): asynchat.async_chat.__init__(self, conn) self.__server = server self.__conn = conn self.__addr = addr +self.__size = size self.__line = [] self.__state = self.COMMAND self.__greeting = 0 @@ -122,6 +128,7 @@ self.__data = '' self.__fqdn = socket.getfqdn() self.__peer = conn.getpeername() +self.__8bitmime = False print('Peer:', repr(self.__peer), file=DEBUGSTREAM) self.push('220 %s %s' % (self.__fqdn, __version__)) self.set_terminator(b'\r\n') @@ -153,7 +160,7 @@ arg = line[i+1:].strip() method = getattr(self, 'smtp_' + command, None) if not method: -self.push('502 Error: command %s not implemented' % command) +self.push('500 Error: command %s not recognized' % command) return method(arg) return @@ -162,7 +169,7 @@ self.push('451 Internal confusion') return # Remove extraneous carriage returns and de-transparency according -# to RFC 821, Section 4.5.2. +# to RFC 5321, Section 4.5.2. data = [] for text in line.split('\r\n'): if text and text[0] == '.': @@ -170,18 +177,39 @@ else: data.append(text) self.__data = NEWLINE.join(data) -status = self.__server.process_message(self.__peer, - self.__mailfrom, - self.__rcpttos, - self.__data) -self.__rcpttos = [] -self.__mailfrom = None -self.__state = self.COMMAND -self.set_terminator(b'\r\n') -if not status: -self.push('250 Ok') + +# Enforce data size limit +if self.__size == 0 or len(self.__data) = self.__size
[issue9168] setuid in smtp.py sheds privileges before binding port
New submission from Alberto Trevino albe...@byu.edu: The SMTP proxy server in Python (smtpd.py) allows you to shed privileges and run as user nobody. However, if you are trying to use port 25, the server will shed privileges before binding the port, causing a bind failure. By moving the setuid code between the creation of the proxy server and the aysncore loop, we can bind a port below 1024 and run as nobody. -- components: Library (Lib) files: smtpd.py-0.2-setuid-fix.diff keywords: patch messages: 109336 nosy: alfmel, barry priority: normal severity: normal status: open title: setuid in smtp.py sheds privileges before binding port versions: Python 3.2 Added file: http://bugs.python.org/file17871/smtpd.py-0.2-setuid-fix.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9168 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8739] Update to smtpd.py to RFC 5321
Alberto Trevino albe...@byu.edu added the comment: What is the status of this patch? Is there anything else I need to do? Any remaining concerns that would stop this patch from being merged? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8739 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8739] Update to smtpd.py to RFC 5321
Alberto Trevino albe...@byu.edu added the comment: On Thursday 20 May 2010 07:46:43 am you wrote: If you don't specify the size, the response of EHLP won't list SIZE as one of the extensions. But, if a size is specified, then it will show it on EHLP. Sorry, the EHLP above should be EHLO. Fat fingers, little sleep, talk about help... you get the idea. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8739 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8739] Update to smtpd.py to RFC 5321
Alberto Trevino albe...@byu.edu added the comment: I have attached a version 2 of the patch. This patch includes everything in the first version, and adds the following: - Support for help arguments (HELP MAIL, for example) - Support for setting the maximum message size from the command line This last feature adds the -s or --size option to the command line. It allows the user to specify the maximum size for the message. It is set to 0 for the default, meaning no limit. This mimics the original behavior of module. If you specify a size (like --size 32768), it will reject messages larger than the specified number of bytes (32KiB in this case). If you don't specify the size, the response of EHLP won't list SIZE as one of the extensions. But, if a size is specified, then it will show it on EHLP. Hopefully these two changes will address some of the concerns that have been brought up. -- Added file: http://bugs.python.org/file17415/smtpd.py-0.2-rfc5321-enhancements-2.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8739 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8738] cPickle dumps(tuple) != dumps(loads(dumps(tuple)))
New submission from Alberto Planas Domínguez apla...@gmail.com: Sometimes, when I use cPickle to serialize tuples of strings, I get different dumps() result for the same tuple: import cPickle t = ('s', 'JOHN') s1 = cPickle.dumps(t) s2 = cPickle.dumps(cPickle.loads(cPickle.dumps(t))) assert s1 == s2 # AssertionError With cPickle doesn't matter what protocol use por dumps(). The assertion is Ok if I use the pickle module instead of cPickle. This means that I can't use a serialized object as a key in a map/dict object. -- messages: 105896 nosy: Alberto.Planas.Domínguez priority: normal severity: normal status: open title: cPickle dumps(tuple) != dumps(loads(dumps(tuple))) type: behavior versions: Python 2.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8738 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8739] Update to smtpd.py to RFC 5321
New submission from Alberto Trevino albe...@byu.edu: This patch updates smtpd.py to be more RFC 5321 compliant. It contains: - EHLO support - Implement DATA size limit (32 MiB by default) - 8-bit mime extension plumbing (doesn't do anything, but accepts and records command) - Basic VRFY support - Basic HELP support - A few improvements to messages (more in line with RFC 5321 examples) - Misc. documentation updates The patch is specific to Python 3.1. I have not tried to backport the changes to 2.x. If possible, I would like the patch to be considered for inclusion to 3.2. -- components: Library (Lib) files: smtpd.py-0.2-rfc5321-enhancements.diff keywords: patch messages: 105902 nosy: alfmel, barry priority: normal severity: normal status: open title: Update to smtpd.py to RFC 5321 type: feature request versions: Python 3.1, Python 3.2 Added file: http://bugs.python.org/file17380/smtpd.py-0.2-rfc5321-enhancements.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8739 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Most efficient way to pre-grow a list?
Quoting Bruno Desthuilliers bdesth.quelquech...@free.quelquepart.fr: Another situation where one may want to do this is if one needs to initialize a non-sparse array in a non-sequential order, Then use a dict. Ok, he has a dict. Now what? He needs a non-sparse array. -- Luis Zarrabeitia Facultad de Matemática y Computación, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu -- http://mail.python.org/mailman/listinfo/python-list
Re: id( ) function question
It's believable if id({}) does the following: 1. Construct an empty dict 2. Take the id of the dict 3. Reduce the reference-count on the now-unneeded dict. It's not too hard for the second empty dict to get allocated in the same memory that the first one (now dereferenced and deallocated) used, so CPython gives it the same id value. Wow, I never thought about it, but at least in my system, it seems to work like that: In [6]: id({1:2}) == id({3:4}) Out[6]: True Interesting... (only as a curiosity, though... One shouldn't rely on that) -- Luis Zarrabeitia Facultad de Matemática y Computación, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu -- http://mail.python.org/mailman/listinfo/python-list
Re: Subclass dynamically
Quoting Robert Dailey rcdai...@gmail.com: Hey, I have a class that I want to have a different base class depending on a parameter that I pass to its __init__method. For example (pseudocode): 1- Are you sure that you want that behavior? Given that in python, a class is just a particular case of invocable object, you could just write a function instead, and the code may be more robust. 2- If you are /sure/ that is the behavior you want, take a look at the __new__ method. The __new__ can decide which instance to return (you could even define a new class inside of it, instantiate it, and return the instance). 3- You may want to take a look at metaclasses. But without more details about why you want it, I can't give you more precise answers. Regards, -- Luis Zarrabeitia Facultad de Matemática y Computación, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu -- http://mail.python.org/mailman/listinfo/python-list
Re: initializing with empty list as default causes freaky problems
Quoting Reckoner recko...@gmail.com: Hi, Observe the following: In [202]: class Foo(): .: def __init__(self,h=[]): .: self.h=h [...] In [207]: f.h.append(10) In [208]: f.h Out[208]: [10] In [209]: g.h Out[209]: [10] The question is: why is g.h updated when I append to f.h? Shouldn't g.h stay []? What you are seeing is basically the same that happens here: === In [1]: def f(l=[]): ...: l.append(1) ...: print l ...: In [2]: f() [1] In [3]: f() [1, 1] In [4]: f() [1, 1, 1] === The problem is that the default value [] is evaluated only once, at function creation time, and not at invocation. Thus, every call to the function shares the same default object. That is consistent with python's function type: the def construct just creates a function object and initializes it with the code, argument list and default values. That means that the default value are part of the function object itself, regardless of when/if it is called: === In [5]: f.func_defaults Out[5]: ([1, 1, 1],) === The recommended way of dealing with this case (mutable default arguments) is: def f(l = None): if l is None: l = [] # the code goes here. (in your case, your g.__init__ and f.__init__ methods share the same Foo.__init__ function, and thus, share the same default value []) That is a very common python gotcha, and I think it is well documented in the standard doc (but I can't find it right now, sorry). Unfortunately, it doesn't become intuitive until you've spent a while understanding python's execution model (and then you suddenly realize that it just makes sense). [And now I wonder... how other languages do it? I've spent so much time with python that reevaluating the default argument on invocation feels clumsy, but I'm obviously tainted now...] Regards, -- Luis Zarrabeitia Facultad de Matemática y Computación, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu -- http://mail.python.org/mailman/listinfo/python-list
Re: Help understanding the decisions *behind* python?
Quoting Inky 788 inky...@gmail.com: The good reason is the immutability, which lets you use a tuple as a dict key. Thanks for the reply Hendrik (and Steven (other reply)). Perhaps I'm just not sophisticated enough, but I've never wanted to use a list/ tuple as a dict key. This sounds like obscure usage, and a bit contrived as a reason for having *both* lists and tuples. I don't seem to understand your definition of obscure and contrived. It seems that you got late to this thread, and you missed the examples. I'd suggest you to go back on this thread and look at them. heights = {} heights[1,2] = 5 heights[1,3] = 7 heights[3,5] = 1 addresses[lastname, firstname] = my_home_address census[location, age] = census.get((location, age), 0) + 1 All those are using tuples as dict keys. Regards, -- Luis Zarrabeitia Facultad de Matemática y Computación, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu -- http://mail.python.org/mailman/listinfo/python-list
Re: missing 'xor' Boolean operator
Quoting Jean-Michel Pichavant jeanmic...@sequans.com: Emile van Sebille wrote: On 7/16/2009 7:04 AM Unknown said... On 2009-07-16, Emile van Sebille em...@fenx.com wrote: daysInAdvance = int(inputVar) or 25 I don't get it. That doesn't work right when inputVar == 0. Aah, but you didn't get to define right. :) For that particular example 0 is not a valid response. When I was talking about such error prone form of boolean operations, I didn't expect to be right so quickly :p What do you mean by being right so quickly, and error prone in this context? I would also ask Unknown why he believes that int(intputVar) or 25 doesn't work right when inputVar == 0. The only false value that int() may return is zero, so the or 25 clause is there only for that case. I can't see then how you think that is an error. I'm not sure it makes sens anyway. I mean, I could easily argue that the number 0 is something. In the end I wonder if I shouldn't just acknowledge the python mechanism Then look it another way. The Empty/Nothing is just standard practice, there is nothing in python that forces you to be false if you are empty, or true otherwise. Instead, answer this: why do you need a /boolean/ value? Is there any case where you need to be certain that the object's type is 'bool'? If you think the answer is yes, you may want to get more familiar with the duck typing concept. (That doesn't mean that there are no legitimate cases where duck typing is inappropriate, but that there are many cases where people, specially if they come from statically typed languages, may believe that it is inappropriate when it isn't). In the python world, one should care more about how an object /behaves/ than from what clase it came. If something quacks like a duck, then assume that it is a duck, at least for the quacking part. Most python objects carry a truth value. Sometimes it feels natural (None is false, boolean True and False are true and false, empty containers are expected to be false, 0 and '' are false). Sometimes, it is everything but natural, but that's a problem with the object's implementation (datetime.time comes to mind). So, you shouldn't care if you have a bool instance - it should be enough that it behaves like a bool (though, if you need a bool, you can always construct one). The True or False expression could return Giraffes, as long as Giraffes behave like the bool True in boolean context. If you care about the class of the result, you can ask for its truth value, and if you don't care about it, you can just ignore it, and use it as you would use a bool. And then, if you can return any object as long as it behaves properly, what would be better to return? A new bool? Why not new Giraffe, if they will have the same behaviour? Guido chose to return the a value that will say more about the result of the operation than just a boolean. It acts as a boolean - if you don't need anything else, treat it as such -, but it will be, whenever is possible, one of the objects in the sequence, in case you need more info. without trying to find any intuitive/natural/obvious logic in it, knowing that sometimes the Truth lies far away from the Evidence. Don't do that. Many of python's decisions are very well thought. You may disagree with them, as I do with some, but they are rarely taken lightly. And this is one that I find very agreeable and in line with the rest of python's philosophy. -- Luis Zarrabeitia Facultad de Matemática y Computación, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu -- http://mail.python.org/mailman/listinfo/python-list
Re: Exotic Logics
Quoting Lie Ryan lie.1...@gmail.com: pdpi wrote: On Jun 17, 5:37 pm, Lie Ryan lie.1...@gmail.com wrote: Steven D'Aprano wrote: On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: I was staring at a logic table the other day, and I asked myself, what if one wanted to play with exotic logics; how might one do it? This might be useful for you, and if not useful, at least it might blow your mind like it did mine. (This is not original to me -- I didn't create it. However, I can't find the original source.) Imagine for a moment that there are no boolean values. There are no numbers. They were never invented. There are no classes. There are no objects. There are only functions. Could you define functions that act like boolean values? And could you define other functions to operate on them? [basic lambda calculus definitions] [...] What I meant was: if you can pass a function as an argument to another function, that means either: 1) you must use function pointer (numbers) or 2) function is a first-class object. Both violates the restriction (no number and no object respectively). Even after abandoning the semantics of functions in python, going to function as in purely mathematical sense, I still am not convinced (warning: I don't know lambda calculus, although I program in heavily functional style). You are confusing semantics with implementation. At some point, of course one would need to use real object (at the lowest level, the computer I'm typing this in is a physical object). But the interesting part is that you can define the whole logic system using nothing but functions. You may need to implement it using objects, or maybe you could devise a machine that will behave like that using only sticks on the floor, but that doesn't matter. From the user's perspective, there would be only functions: no strings, no objects, no numbers. That reminds me of my last class (disclaimer: I teach discrete math). I told my students well, let's assume that numbers exist, and I wasn't making fun of them... I found that topic easier to understand (computability, primitive recursion) if one ignores the numbers, even if one obviously has to write them somewhere at some point. -- Luis Zarrabeitia Facultad de Matemática y Computación, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding a Par construct to Python?
Quoting Carl Banks pavlovevide...@gmail.com: I don't have any reply to this post except for the following excerpts: On May 20, 8:10 pm, Luis Alberto Zarrabeitia Gomez ky...@uh.cu wrote: 2- in [almost] every other language, _you_ have to be aware of the critical sections when multithreading. [snip] That's not what I said. We are not talking about the _language_, but about one very specific implementation detail. Not even that, I'm talking about one of the reasons presented in favor of that specific implementation detail (while agreeing with the others). [...] No other languages have nesting by indentation (while still being reasonablyt successful) etc Comparisons to other languages are useless here. In many cases Python does things differently from most other languages and usually it's better off for it. You seem to have missed that I'm not talking about the language but about a specific implementation detail of CPython. I thought that my poor choice of words in that sentence was completely clarified by the paragraphs that followed, but apparently it wasn't. In my 2- point, maybe I should've said instead: in [almost] every language, INCLUDING (proper) PYTHON, you have to be aware of critcal sections when multithreading. The fact that other languages do something differently doesn't mean that other way's better, in fact it really doesn't mean anything at all. No, it doesn't mean that it's better, and I didn't say it was. But it _does_ show that it is _possible_. For an argument about how hard could be to write native extensions in there was no GIL, the fact that there are many other GIL-less platforms[1] where is not painful to write native extensions is a valid counter-example. And that, in all those languages and platforms (including python), the only one where I hear that explicit, granular locking is too hard or whatever[2], is CPython's /native/ extensions, is what I found weird. Regards, Luis [1] Including the python implementations for .net and java. [2] Really, this is was my question and nothing more. I was not comparing, I was trying to understand what was that whatever that made it so hard for CPython. And your footnote in the previous message gave me a reasonable explanation. -- Luis Zarrabeitia Facultad de Matemática y Computación, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding a Par construct to Python?
Quoting Carl Banks pavlovevide...@gmail.com: On May 20, 4:07 pm, Luis Zarrabeitia ky...@uh.cu wrote: On Wednesday 20 May 2009 06:16:39 pm Aahz wrote: The designers of Python made a design decision(**) that extension writers would not have to take care of locking. They could have made a different decision, they just didn't. Well, then, maybe that's the only python's decision so far I may not agree with. And I'm not criticizing it... but I'm questioning it, because I honestly don't understand it. There must be another reason (i.e, the refcounts) to argue _for_ the GIL, Why? 1- refcounts is a _very_ strong reason to argue for the GIL. Add to that simplifying CPython implementation, and you don't really need another one on top of that, at least not to convince me, but 2- in [almost] every other language, _you_ have to be aware of the critical sections when multithreading. Even in pure python, you have use locks. Don't you find at least a bit odd the argument that in the particular case you are writing a C extension from python, you should be relieved of the burden of locking? because this one just seems to be just an attempt to fix unsafe code when called from python. I think you are being unfair in calling it unsafe. I think I was unfair calling it a fix. It sounds like it was broken, my bad. I should have used 'not multithread-ready'. Suppose if I were to call PyList_Append from a C extension. It's not necessary for me to guard the list I'm calling it on with a lock, because only the GIL thread is allowed to call most Python API or otherwise access objects. But you seem to be suggesting that since I didn't guard the list with a lock it is unsafe, even though the GIL is sufficient? Certainly not. If you program under the assumption that you have a GIL, of course it is not unsafe. Not your code, anyway. But, why is PyList_Append not multithread-ready? (or rather, why does PyList_Append would requiere a _global_ lock to be multithread ready, instead of a more local lock?) Of course, given that the GIL exists, to use it is the easier solution, but for this particular case, it feels like discarding multithreading just to avoid locking. No, I totally disagree. The code is not unsafe and the GIL doesn't fix it. The code is jsut [I think there was a word missing from that sentence...) And that was my point. Refcounts + interpreter simplicity seem to imply the need for a GIL, but to make unsafe code safe without fixing said code (or even thinking about it) is a weird goal... Why? Do you seriously not see the benefit of simplifying the work of extention writers and core maintainers? You don't have to agree that it's a good trade-off but it's a perfectly reasonable goal. I do agree that, at least for the core maintainers, it is a good trade-off and a reasonable goal to keep CPython simple. And if that has, as a positive side efect for extensions writers, that their code becomes easier, so be it. What I don't agree - rather, what I don't understand, is why it is presented in the opposite direction. I highly suspect Aahz here would argue for a GIL even without the refcount issue, and even though I wouldn't agree, there's nothing weird or unreasonable about the argument, it's just a different viewpoint. I consider it weird, at least. If I were to say that python should not allow multithreading to simplify the lives of pure-python programmers, I hope I would be shot down and ignored. But somehow I must consider perfectly natural the idea of not allowing[1] multithreading when building C extensions, to simplify the lives of extension programmers. specially if it became the only reason for a GIL. After all, one could argue for that goal in almost all languages. B-B-B-But other languages do it that way! is not a big factor in language decisions in Python. That's not what I said. We are not talking about the _language_, but about one very specific implementation detail. Not even that, I'm talking about one of the reasons presented in favor of that specific implementation detail (while agreeing with the others). The fact that the reason I'm having trouble with is valid for almost any other language, and none of them have a GIL-like construct (while still being successful, and not being exceptionally hard to build native modules for) just suggests that _that_ particular reason for that particular implementation detail is not a very strong one, even if all other reasons are. (**) - To be fair, Python didn't originally support threads, so there was a lot of code that would have become unsafe had threading been added without the GIL, and that probably influenced the decision to use a GIL, but I'm sure that wasn't only reason. Would Python have a GIL if threading had been there from the start? Who knows. (This is a very good remmark. Maybe here lies the whole answer to my question. We may be dragging the heavy chain of backward compatibility
Re: pushback iterator
Quoting Mike Kazantsev mk.frag...@gmail.com: And if you're pushing back the data for later use you might just as well push it to dict with the right indexing, so the next pop won't have to roam thru all the values again but instantly get the right one from the cache, or just get on with that iterable until it depletes. What real-world scenario am I missing here? Other than one he described in his message? Neither of your proposed solutions solves the OP's problem. He doesn't have a list (he /could/ build a list, and thus defeat the purpose of having an iterator). He /could/ use alternative data structures, like the dictionary you are suggesting... and he is, he is using his pushback iterator, but he has to include it over and over. Currently there is no good pythonic way of building a functions that decide to stop consuming from an iterator when the first invalid input is encountered: that last, invalid input is lost from the iterator. You can't just abstract the whole logic inside the function, something must leak. Consider, for instance, the itertools.dropwhile (and takewhile). You can't just use it like i = iter(something) itertools.dropwhile(condition, i) # now consume the rest Instead, you have to do this: i = iter(something) i = itertools.dropwhile(condition, i) # and now i contains _another_ iterator # and the first one still exists[*], but shouldn't be used # [*] (assume it was a parameter instead of the iter construct) For parsing files, for instance (similar to the OP's example), it could be nice to do: f = file(something) lines = iter(f) parse_headers(lines) parse_body(lines) parse_footer(lines) which is currently impossible. To the OP: if you don't mind doing instead: f = file(something) rest = parse_headers(f) rest = parse_body(rest) rest = parse_footer(rest) you could return itertools.chain([pushed_back], iterator) from your parsing functions. Unfortunately, this way will add another layer of itertools.chain on top of the iterator, you will have to hope this will not cause a performace/memory penalty. Cheers, -- Luis Zarrabeitia Facultad de Matemática y Computación, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu -- http://mail.python.org/mailman/listinfo/python-list
Re: Self function
Quoting Rhodri James rho...@wildebst.demon.co.uk: I'm sorry, but while I'm mildly positive towards the proposal (and more so towards Aaron's decorator), I don't buy this argument at all. What is broken about your editor's global search-and-replace function that makes it usually useless for making these name changes? It happened to me sometimes. If a module defines some functions, and it doesn't *use* them, why should I use a global search-and-replace to rename something? Modifying the def line should be enough - unless the function happens to be recursive. So the answer to my question would be nothing? Indeed, there is nothing broken with the search and replace feature of his editor. When he is copying a non-recursive function, it is _useless_ to do a search and replace. When he is copying a recursive function, it is _required_ to do a search and replace. So, the very same task requires you to either perform a task that will almost always be useless (or even dangerous), or to read the source code to find out if the function is recursive, so that you can use the search and replace only then. (I know that the problem is present in almost all programming languages... but that's not what is being discussed. Bearophile's concerns seem legitimate, and you should not dismiss them so lightly just because there are ways to do more work and hopefully avoid the problems. I'd say that the problem is even aggravated in python, where the dynamic nature of the language makes it near to impossible to build good refactoring tools) -- Luis Zarrabeitia Facultad de Matemática y Computación, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu -- http://mail.python.org/mailman/listinfo/python-list
Re: Self function
Quoting Steven D'Aprano ste...@remove.this.cybersource.com.au: But regardless, everyone is missing the most important point: why are you copying and pasting code in the first place? That is surely very close to the top of the list of Worst Ever Anti-Patterns, and it should be avoided whenever possible. [btw, I took this long before jumping into this thread for this precise reason... Copy/paste is an evil anti-pattern. In Python, we can avoid much copy-and-paste coding with decorators. Given one function, we can create as many variants as we want, differing in pre- processing of arguments and post-processing of results, by using decorators. This is a powerful ability to have, but it's crippled for many recursive functions, because recursive functions in Python don't actually call themselves, they call whatever happens to be bound to their name at runtime. A bit offtopic: a while ago I think I saw a recipe for a decorator that, via bytecode hacks, would bind otherwise global names to the local namespace of the function. Can anyone remember it/point me to it? An @bind decorator that would 'localize' all the global names, including the still unexistent but already know function name, would guarantee that at least recursion calls the same function instead of whatever happens to be bound to their name at runtime. If it wasn't a hack, anyway. -- Luis Zarrabeitia Facultad de Matemática y Computación, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing.Queue - I want to end.
Quoting Cameron Simpson c...@zip.com.au: | And as it happens I have an IterableQueue class right here which does | _exact_ what was just described. You're welcome to it if you like. | Added bonus is that, as the name suggests, you can use the class as | an iterator: | for item in iterq: | ... | The producer calls iterq.close() when it's done. Someone asked, so code appended below. [...] Thank you!. I tested it, and it seems to work... and having the queue be an iterable is a plus. Thank you, Cameron MRAB! -- Luis Zarrabeitia Facultad de Matemática y Computación, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing.Queue - I want to end.
Quoting Hendrik van Rooyen m...@microcorp.co.za: Luis Zarrabeitia akaky...@uh.cu wrote: 8 ---explanation and example of one producer, 8 ---more consumers and one queue As you can see, I'm sending one 'None' per consumer, and hoping that no consumer will read more than one None. While this particular implementation You don't have to hope. You can write the consumers that way to guarantee it. I did. But that solution is not very reusable (I _must_ remember that implementation detail every time) and most important, i'll have to remember it in a few months with I'm updating the code. ensures that, it is very fragile. Is there any way to signal the consumers? Signalling is not easy - you can signal a process, but I doubt if it is possible to signal a thread in a process. (or better yet, the queue itself, as it is shared by all consumers?) Should close work for this? (raise the exception when the queue is exhausted, not when it is closed by the producer). I haven't the foggiest if this will work, and it seems to me to be kind of involved compared to passing a sentinel or sentinels. Well, that would be a vaild signal. Too bad I have to pass it by hand, instead of the queue class taking care of it for me. I have always wondered why people do the one queue many getters thing. Given that the stuff you pass is homogenous in that it will require a similar amount of effort to process, is there not a case to be made to have as many queues as consumers, and to round robin the work? Abstraction. This problem is modeled nicely as a producer-consumer (it would be in fact a classic producer-consumer). I could take care of the scheduling myself, but there are already good scheduling algorithms written for my OS, that take into account both the available CPU and IO. A solution may not be a queue (in my case, I don't care the order in which the elements are processed, only that they are), but ideally I would just be 'yielding' results on my producer(s), and receiving them on my consumer(s), leaving the IPC mechanism to deal with how to move the data from producers to consumers (and to which consumers). And if the stuff you pass around needs disparate effort to consume, it seems to me that you can more easily balance the load by having specialised consumers, instead of instances of one humungous I can eat anything consumer. Not necessarily. The load may depend on the size of the data that was sent. The consumers are receiving the same kind of data, only the sizes are different (non-predictable different). Again, I could try to implement some heuristics to try and guess what processor has lower load, but I'd rather delegate that to the OS. I also think that having a queue per consumer thread makes it easier to replace the threads with processes and the queues with pipes or sockets if you need to do serious scaling later. This is already multiprocess. It could be nice to extend it to multi-computers later, but the complexity is not worth it right now. In fact I happen to believe that anything that does any work needs one and only one input queue and nothing else, but I am peculiar that way. Well, I also need some output. In my case, the outputs are files with the result of the processing, that can be summarized later (hence the need to 'join' the processes, to know when I can summarize them). Thank you. -- Luis Zarrabeitia Facultad de Matemática y Computación, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu -- http://mail.python.org/mailman/listinfo/python-list