barbos
Contributor
fscanf is a library function in C. You can easily write it in python if you want.One problem is Python does not appear to have a formatted file read similar to C fscanf()
fscanf is a library function in C. You can easily write it in python if you want.One problem is Python does not appear to have a formatted file read similar to C fscanf()
.fscanf is a library function in C. You can easily write it in python if you want.One problem is Python does not appear to have a formatted file read similar to C fscanf()
I lost currency with Windows a way back.Sadly, I see a window open, which immediately closes.
Yes, python is wastely more powerful when it comes to text processing..fscanf is a library function in C. You can easily write it in python if you want.One problem is Python does not appear to have a formatted file read similar to C fscanf()
Actually the Python array read and write functions I posted are essentially fprintf() and fscanf().
Examples of passing variable numbers of arguments to a function with a format string.
def adf(a,b):
return a + b
import math
import os
os.chdir('c:\\python')
from test1 import adf
x = adf(6,3)
print(x)
In C++
class x{
private:
int b = 345
public:
int a = 0
void f1(void){
return a*b
}
void f2(int x){
b = x
}
};
x.f2(123)
x.a = 123
cout<<x.f1()
b can not be accessed or changed from outside the c;lss
In Python
class x:
a = 0
def f():
return x.a
x.a = 123
print(x.f())
import math
func = 'log(10)'
f = ''
arg = ''
n = len(func)
for i in range(n):
if func[i] == '(': break
f += func[i]
print(f)
for j in range(i+1,n):
if func[j] == ')': break
arg += func[j]
print(arg)
num = 0
match f:
case 'log': num = math.log(float(arg))
case _:print('No Match')
print(num)
import math
import os
os.system('cls')
def make_sin(n,tmax,x,y):
dt = tmax/(n-1.)
t = 0
for i in range(n):
x[i] = t
y[i] = math.sin(t)
t += dt
def save_nums(fname,delim,*args):
nrows = len(args[0])
# check number of rows the same
for i in range(len(args)):
if len(args[i]) != nrows : return 'Rows Mismatch'
f = open(fname,'w')
for i in range(nrows):
s = ' ' # row string
j = 0
for x in args:
s += repr(x[i])
if j < len(args)-1:s += delim
j += 1
s += '\n'
f.write(s)
f.close()
return 'Save Complete'
ns = 100
ys = ns*[0]
xs = ns*[0]
tmax = math.pi*2
make_sin(ns,tmax,xs,ys)
fn = 'c:\\python\\datas.csv'
delm = ','
w = save_nums(fn,delm,xs,ys)
print(w)
I used c/c++ and a scripted language in a math tool Scilab. Other than that I was ignorant of anything else.Well Javascript is the top language by usage, but that's because it has a monopoly in the browser, not because it's good.
import math
import random
def set_dec_places(x,y,dp,t):
#maintains original numbers
#shift dec point right
#truncate or round up
#restore dec point
n = len(x)
shift = pow(10,dp) #dec point shift
for i in range(n):
match t:
case 'i':y[i] = int(x[i]*shift) #truncate
case 'r':y[i] = round(x[i]*shift) #round up
y[i] = y[i]/shift #restore dec point
#test with random numbers
n = 100
z = n*[0]
zr = n*[0]
dp = 2
for i in range(n):
z[i] = random.uniform(0,100)
set_dec_places(z,zr,dp,'r')
for i in range(n):
print('%f %f' %(z[i],zr[i]))
Check out matplotlib.I used c/c++ and a scripted language in a math tool Scilab. Other than that I was ignorant of anything else.Well Javascript is the top language by usage, but that's because it has a monopoly in the browser, not because it's good.
If I had been aware of it I might have used Python. It has similar math libs to Scilab, but lacks the native graphics and data representation. For math I coded in C and used Scilab for graphics.
That's OK I guess, but pip works better:I use a general-purpose open-source archive for all my Python add-ons. Be careful when using one of these that you use the ones for whichever version of Python that you have.
MacOS ones: Homebrew — The Missing Package Manager for macOS (or Linux) and The MacPorts Project -- Home and Fink - Home
Linux ones are usually included in whichever distribution that one is using.
Free/Open-Source package managers for Windows? please share your experience. : windows - listing several of them