Can anyone share experience about python backend developer?
I have 3+years developer experience in python, but I always develop about peer-to-peer service. Have no backend experience in python. But now I want to change to backend engineer, somebody shares their job is to do like 1. Develop customize API to receive data from global 2. Develop tools with k8s 3. Experience about NoSQL After I heard above, it seems wide range and hard to start from scratch. Without comparing performance with other languages, how to dig into backend development?(Or some framework could help me?) thx -- https://mail.python.org/mailman/listinfo/python-list
Re: What I learned today
[email protected] (Stefan Ram) writes: > ... > But the book told me that you can unzip using ... »zip« again! > > z = zip( x, y ) > a, b = zip( *z ) > print( a ) > ('y', 'n', 'a', 'n', 't') > print( b ) > (4, 2, 7, 3, 1) > > Wow! Usally i use zip so many, thanks for tip^^^ Sincerely, Byung-Hee -- ^고맙습니다 _地平天成_ 감사합니다_^))// -- https://mail.python.org/mailman/listinfo/python-list
insert data in python script
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 plotcubic: bool plot cubic polynomial in compressibility factor
:param printresults: bool print off properties
Returns a Dict() of molecule properties at this T and f.
"""
# build function to minimize: difference between desired fugacity and that
obtained from preos
def g(P):
"""
:param P: pressure
"""
return (f - preos(molecule, T, P, plotcubic=False,
printresults=False)["fugacity(bar)"])
# Solve preos for the pressure
P = newton(g, f) # pressure
# Obtain remaining parameters
pars = preos(molecule, T, P, plotcubic=plotcubic, 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
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
Re: fugacity cofficient
On Sun, 16 Feb 2020 14:17:28 -0800 (PST), alberto wrote: > Hi, > how I could realize a script to calculate fugacity coefficients > with this formula > [snip] > > regards > > Alberto Welcome, Alberto. Can you make this look more like a Python question and less like a do-my-homework question? Show us what you've tried. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: fugacity cofficient
On 17 Feb 2020 18:40:00 GMT, Peter Pearson wrote: > > Welcome, Alberto. > > Can you make this look more like a Python question and less like a > do-my-homework question? Show us what you've tried. Sorry. I see you already did exactly that. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: I can't access dataframe fields
Hi MRAB, I changed last_cluster to tuple(last_cluster). From: print (updated_distance_matrix_df.loc [clusters [i], last_cluster]) to print (updated_distance_matrix_df.loc [clusters [i], tuple(last_cluster)]) And worked. Thank you, Markos Em 15-02-2020 23:36, MRAB escreveu: On 2020-02-16 00:50, Markos wrote: Hi all, I created the following data frame (updated_distance_matrix) P1 P2 P4 P5 (P3, P6) P1 0,00 0,244307 0,367696 0,341760 0 P2 0.234307 0.00 0.194165 0.1443178 0 P4 0.366969 0.194165 0.00 0.284253 0 P5 0.341760 0.1443178 0.284253 0.00 0 (P3, P6) 0.00 0.00 0.00 0.00 0 I can change the fields of columns and rows P1-P5 without problems. But when I try to access the fields of the row, or column, (P3, P6) print (updated_distance_matrix_df.loc [clusters [i], last_cluster]) the message appears: KeyError: 'the label [P3, P6] is not in the [index]' The rows and columns have "(P3, P6)", but you're looking for "[P3, P6]". They aren't the same. If I change find the "loc" by "at" method appears the error: print (updated_distance_matrix_df.at [clusters [i], last_cluster]) TypeError: unhashable type: 'list' Is it expecting a tuple instead of a list? Tuples are hashable, lists are not. And if you simply leave: print (updated_distance_matrix_df [clusters [i], last_cluster]) gives the error: TypeError: unhashable type: 'list' A last_cluster variable is of type list: print (last_cluster, type (last_cluster)) ['P3', 'P6'] And a variable cluster [i] is a string: print (clusters [i], type (clusters [i])) P5 Any tip? Thank you, -- https://mail.python.org/mailman/listinfo/python-list
Interpreter Python 3.8 not there to select from PyCharm
I'm very new to Python and wanting to learn the basics. I downloaded and installed Python 3.8 and PyCharm for my Windows 10 machine. All good. Launched PyCharm and I started a new Project and tried to select an 'interpreter' such as Python 3.8 but no interpreter was available for me to select from the down arrow menu ..!?!? Any settings I need to do ?? Thanks, Maxime -- https://mail.python.org/mailman/listinfo/python-list
Re: Can anyone share experience about python backend developer?
On 17/02/20 11:11 PM, lampahome wrote: I have 3+years developer experience in python, but I always develop about peer-to-peer service. Have no backend experience in python. But now I want to change to backend engineer, somebody shares their job is to do like 1. Develop customize API to receive data from global 2. Develop tools with k8s 3. Experience about NoSQL After I heard above, it seems wide range and hard to start from scratch. Without comparing performance with other languages, how to dig into backend development?(Or some framework could help me?) Suggest a review of edX's and Coursera's (and possibly others) on-line training courses. IIRC there's at least one that aims specifically at the 'back-end' stack. -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list
Re: insert data in python script
Please help us to help you!
1 is all of this code in a single file or spread across (at least) two
modules? What are their names? What is the directory structure?
2 copy-paste the actual error message received.
It works for me!
1 not knowing your circumstances, I put all the code in one file
2 updated one line (possibly due to above)
# methane = preos.Molecule("methane", -82.59 + 273.15, 45.99, 0.011)
methane = Molecule("methane", -82.59 + 273.15, 45.99, 0.011)
dn $ python3 Projects/molecule.py
Molecule: methane.
Critical Temperature = 190.6 K
Critical Pressure = 46.0 bar.
Accentric factor = 0.011000
NB if the bulk of the code is stored in a module named preos.py then it
is necessary to first:
import peos
and restore the above change.
NBB under such conditions peos.py must be located in the file-system
where the 'mainline' can find (and import) it!
--
Regards =dn
--
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 plotcubic: bool plot cubic polynomial in compressibility factor
> :param printresults: bool print off properties
> Returns a Dict() of molecule properties at this T and f.
> """
> # build function to minimize: difference between desired fugacity and
> that obtained from preos
> def g(P):
> """
> :param P: pressure
> """
> return (f - preos(molecule, T, P, plotcubic=False,
> printresults=False)["fugacity(bar)"])
>
> # Solve preos for the pressure
> P = newton(g, f) # pressure
>
> # Obtain remaining parameters
> pars = preos(molecule, T, P, plotcubic=plotcubic,
> printresults=printresults)
> rho = pars["density(mol
