Help...

A forum for general discussion of the Python programming language.

Help...

Postby alabview » Wed Oct 23, 2013 3:42 pm

Hi there,

I have two issues here see below,

1. I have a STRING i.e. "CLOSEDLOOP{DCSOURCE1|VOLTAGE|CH1|0.01|0.1|5|1000}" and use 0.01,0.1 and 5 as a For Loop i.e. 0.1 to 5 with increment by 0.01 and no idea how to do it.

Please advice.

MAny Thanks.
Walter.
alabview
 
Posts: 22
Joined: Mon Sep 16, 2013 1:48 pm

Re: Help...

Postby Marbelous » Wed Oct 23, 2013 5:32 pm

That's only one issue. ;)

You need to parse the values from your string and use them for loop variables. If the string format is consistent this is pretty easy.
For example try the split method which works on strings:
Code: Select all
 "CLOSEDLOOP{DCSOURCE1|VOLTAGE|CH1|0.01|0.1|5|1000}".split('|')


That will return a list you can index to get your values.
Marbelous
 
Posts: 127
Joined: Fri May 31, 2013 8:12 pm

Re: Help...

Postby ochichinyezaboombwa » Wed Oct 23, 2013 7:39 pm

I didn't understand what is your 1st issue (you didn't tell us); as for the 2nd one, I'd do something like this:
Code: Select all
for i in range(5*100):
    print "i: %.2f" % ( i/100.) # or do whatever you want with 0.00, 0.01
ochichinyezaboombwa
 
Posts: 200
Joined: Tue Jun 04, 2013 7:53 pm

Re: Help...

Postby alabview » Thu Oct 24, 2013 3:52 pm

Hi ochichinyezaboombwa,

Thanks for your answer, awesome!!

But, I have problem again...
Code: Select all
>>>import ctypes
>>>for i in range(5*100):
   RANGE=ctypes.c_double(i/100.)
   print(RANGE)


Answer is
Code: Select all
c_double(0.0)
c_double(0.01)
c_double(0.02)
c_double(0.03)
c_double(0.04)
c_double(0.05)
c_double(0.06)
c_double(0.07)
c_double(0.08)
c_double(0.09)
c_double(0.1)
c_double(0.11)
c_double(0.12)
c_double(0.13)
c_double(0.14)
c_double(0.15)
c_double(0.16)
c_double(0.17)
c_double(0.18)
c_double(0.19)
c_double(0.2)
c_double(0.21)
c_double(0.22)
c_double(0.23)
c_double(0.24)
c_double(0.25)
c_double(0.26)
c_double(0.27)
c_double(0.28)
c_double(0.29)
c_double(0.3)
c_double(0.31)
c_double(0.32)
c_double(0.33)
c_double(0.34)
c_double(0.35)
c_double(0.36)
c_double(0.37)
c_double(0.38)
c_double(0.39)
c_double(0.4)
c_double(0.41)
c_double(0.42)
c_double(0.43)
c_double(0.44)
c_double(0.45)
c_double(0.46)
c_double(0.47)
c_double(0.48)
c_double(0.49)
c_double(0.5)
c_double(0.51)
c_double(0.52)
c_double(0.53)
c_double(0.54)
c_double(0.55)
c_double(0.56)
c_double(0.57)
c_double(0.58)
c_double(0.59)
c_double(0.6)
c_double(0.61)
c_double(0.62)
c_double(0.63)
c_double(0.64)
c_double(0.65)
c_double(0.66)
c_double(0.67)
c_double(0.68)
c_double(0.69)
c_double(0.7)
c_double(0.71)
c_double(0.72)
c_double(0.73)
c_double(0.74)
c_double(0.75)
c_double(0.76)
c_double(0.77)
c_double(0.78)
c_double(0.79)
c_double(0.8)
c_double(0.81)
c_double(0.82)
c_double(0.83)
c_double(0.84)
c_double(0.85)
c_double(0.86)
c_double(0.87)
c_double(0.88)
c_double(0.89)
c_double(0.9)
c_double(0.91)
c_double(0.92)
c_double(0.93)
c_double(0.94)
c_double(0.95)
c_double(0.96)
c_double(0.97)
c_double(0.98)
c_double(0.99)
c_double(1.0)
c_double(1.01)
c_double(1.02)
c_double(1.03)
c_double(1.04)
c_double(1.05)
c_double(1.06)
c_double(1.07)
c_double(1.08)
c_double(1.09)
c_double(1.1)
c_double(1.11)
c_double(1.12)
c_double(1.13)
c_double(1.14)
c_double(1.15)
c_double(1.16)
c_double(1.17)
c_double(1.18)
c_double(1.19)
c_double(1.2)
c_double(1.21)
c_double(1.22)
c_double(1.23)
c_double(1.24)
c_double(1.25)
c_double(1.26)
c_double(1.27)
c_double(1.28)
c_double(1.29)
c_double(1.3)
c_double(1.31)
c_double(1.32)
c_double(1.33)
c_double(1.34)
c_double(1.35)
c_double(1.36)
c_double(1.37)
c_double(1.38)
c_double(1.39)
c_double(1.4)
c_double(1.41)
c_double(1.42)
c_double(1.43)
c_double(1.44)
c_double(1.45)
c_double(1.46)
c_double(1.47)
c_double(1.48)
c_double(1.49)
c_double(1.5)
c_double(1.51)
c_double(1.52)
c_double(1.53)
c_double(1.54)
c_double(1.55)
c_double(1.56)
c_double(1.57)
c_double(1.58)
c_double(1.59)
c_double(1.6)
c_double(1.61)
c_double(1.62)
c_double(1.63)
c_double(1.64)
c_double(1.65)
c_double(1.66)
c_double(1.67)
c_double(1.68)
c_double(1.69)
c_double(1.7)
c_double(1.71)
c_double(1.72)
c_double(1.73)
c_double(1.74)
c_double(1.75)
c_double(1.76)
c_double(1.77)
c_double(1.78)
c_double(1.79)
c_double(1.8)
c_double(1.81)
c_double(1.82)
c_double(1.83)
c_double(1.84)
c_double(1.85)
c_double(1.86)
c_double(1.87)
c_double(1.88)
c_double(1.89)
c_double(1.9)
c_double(1.91)
c_double(1.92)
c_double(1.93)
c_double(1.94)
c_double(1.95)
c_double(1.96)
c_double(1.97)
c_double(1.98)
c_double(1.99)
c_double(2.0)
c_double(2.01)
c_double(2.02)
c_double(2.03)
c_double(2.04)
c_double(2.05)
c_double(2.06)
c_double(2.07)
c_double(2.08)
c_double(2.09)
c_double(2.1)
c_double(2.11)
c_double(2.12)
c_double(2.13)
c_double(2.14)
c_double(2.15)
c_double(2.16)
c_double(2.17)
c_double(2.18)
c_double(2.19)
c_double(2.2)
c_double(2.21)
c_double(2.22)
c_double(2.23)
c_double(2.24)
c_double(2.25)
c_double(2.26)
c_double(2.27)
c_double(2.28)
c_double(2.29)
c_double(2.3)
c_double(2.31)
c_double(2.32)
c_double(2.33)
c_double(2.34)
c_double(2.35)
c_double(2.36)
c_double(2.37)
c_double(2.38)
c_double(2.39)
c_double(2.4)
c_double(2.41)
c_double(2.42)
c_double(2.43)
c_double(2.44)
c_double(2.45)
c_double(2.46)
c_double(2.47)
c_double(2.48)
c_double(2.49)
c_double(2.5)
c_double(2.51)
c_double(2.52)
c_double(2.53)
c_double(2.54)
c_double(2.55)
c_double(2.56)
c_double(2.57)
c_double(2.58)
c_double(2.59)
c_double(2.6)
c_double(2.61)
c_double(2.62)
c_double(2.63)
c_double(2.64)
c_double(2.65)
c_double(2.66)
c_double(2.67)
c_double(2.68)
c_double(2.69)
c_double(2.7)
c_double(2.71)
c_double(2.72)
c_double(2.73)
c_double(2.74)
c_double(2.75)
c_double(2.76)
c_double(2.77)
c_double(2.78)
c_double(2.79)
c_double(2.8)
c_double(2.81)
c_double(2.82)
c_double(2.83)
c_double(2.84)
c_double(2.85)
c_double(2.86)
c_double(2.87)
c_double(2.88)
c_double(2.89)
c_double(2.9)
c_double(2.91)
c_double(2.92)
c_double(2.93)
c_double(2.94)
c_double(2.95)
c_double(2.96)
c_double(2.97)
c_double(2.98)
c_double(2.99)
c_double(3.0)
c_double(3.01)
c_double(3.02)
c_double(3.03)
c_double(3.04)
c_double(3.05)
c_double(3.06)
c_double(3.07)
c_double(3.08)
c_double(3.09)
c_double(3.1)
c_double(3.11)
c_double(3.12)
c_double(3.13)
c_double(3.14)
c_double(3.15)
c_double(3.16)
c_double(3.17)
c_double(3.18)
c_double(3.19)
c_double(3.2)
c_double(3.21)
c_double(3.22)
c_double(3.23)
c_double(3.24)
c_double(3.25)
c_double(3.26)
c_double(3.27)
c_double(3.28)
c_double(3.29)
c_double(3.3)
c_double(3.31)
c_double(3.32)
c_double(3.33)
c_double(3.34)
c_double(3.35)
c_double(3.36)
c_double(3.37)
c_double(3.38)
c_double(3.39)
c_double(3.4)
c_double(3.41)
c_double(3.42)
c_double(3.43)
c_double(3.44)
c_double(3.45)
c_double(3.46)
c_double(3.47)
c_double(3.48)
c_double(3.49)
c_double(3.5)
c_double(3.51)
c_double(3.52)
c_double(3.53)
c_double(3.54)
c_double(3.55)
c_double(3.56)
c_double(3.57)
c_double(3.58)
c_double(3.59)
c_double(3.6)
c_double(3.61)
c_double(3.62)
c_double(3.63)
c_double(3.64)
c_double(3.65)
c_double(3.66)
c_double(3.67)
c_double(3.68)
c_double(3.69)
c_double(3.7)
c_double(3.71)
c_double(3.72)
c_double(3.73)
c_double(3.74)
c_double(3.75)
c_double(3.76)
c_double(3.77)
c_double(3.78)
c_double(3.79)
c_double(3.8)
c_double(3.81)
c_double(3.82)
c_double(3.83)
c_double(3.84)
c_double(3.85)
c_double(3.86)
c_double(3.87)
c_double(3.88)
c_double(3.89)
c_double(3.9)
c_double(3.91)
c_double(3.92)
c_double(3.93)
c_double(3.94)
c_double(3.95)
c_double(3.96)
c_double(3.97)
c_double(3.98)
c_double(3.99)
c_double(4.0)
c_double(4.01)
c_double(4.02)
c_double(4.03)
c_double(4.04)
c_double(4.05)
c_double(4.06)
c_double(4.07)
c_double(4.08)
c_double(4.09)
c_double(4.1)
c_double(4.11)
c_double(4.12)
c_double(4.13)
c_double(4.14)
c_double(4.15)
c_double(4.16)
c_double(4.17)
c_double(4.18)
c_double(4.19)
c_double(4.2)
c_double(4.21)
c_double(4.22)
c_double(4.23)
c_double(4.24)
c_double(4.25)
c_double(4.26)
c_double(4.27)
c_double(4.28)
c_double(4.29)
c_double(4.3)
c_double(4.31)
c_double(4.32)
c_double(4.33)
c_double(4.34)
c_double(4.35)
c_double(4.36)
c_double(4.37)
c_double(4.38)
c_double(4.39)
c_double(4.4)
c_double(4.41)
c_double(4.42)
c_double(4.43)
c_double(4.44)
c_double(4.45)
c_double(4.46)
c_double(4.47)
c_double(4.48)
c_double(4.49)
c_double(4.5)
c_double(4.51)
c_double(4.52)
c_double(4.53)
c_double(4.54)
c_double(4.55)
c_double(4.56)
c_double(4.57)
c_double(4.58)
c_double(4.59)
c_double(4.6)
c_double(4.61)
c_double(4.62)
c_double(4.63)
c_double(4.64)
c_double(4.65)
c_double(4.66)
c_double(4.67)
c_double(4.68)
c_double(4.69)
c_double(4.7)
c_double(4.71)
c_double(4.72)
c_double(4.73)
c_double(4.74)
c_double(4.75)
c_double(4.76)
c_double(4.77)
c_double(4.78)
c_double(4.79)
c_double(4.8)
c_double(4.81)
c_double(4.82)
c_double(4.83)
c_double(4.84)
c_double(4.85)
c_double(4.86)
c_double(4.87)
c_double(4.88)
c_double(4.89)
c_double(4.9)
c_double(4.91)
c_double(4.92)
c_double(4.93)
c_double(4.94)
c_double(4.95)
c_double(4.96)
c_double(4.97)
c_double(4.98)
c_double(4.99)


So, how to display real value? such as. 0.0,0.01,0.02 & etc and convert those values to c_char_p.or any alternative way to do it? As I need to use c_type function.

MAny Thanks.
alabview
 
Posts: 22
Joined: Mon Sep 16, 2013 1:48 pm

Re: Help...

Postby ochichinyezaboombwa » Mon Oct 28, 2013 9:34 pm

here you go again:
Code: Select all
>>> for i in range(-1,500):
...     print "%.02f" % (ctypes.c_double(i/100.).value)
ochichinyezaboombwa
 
Posts: 200
Joined: Tue Jun 04, 2013 7:53 pm


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 2 guests