Pretty new to Django, but used it blindly and works wonders. But here is a situation I am blocked on for my new project

request.GET the following URL

- Code:
`https://mydesktop.com/validator?hostname1=host1.example.com,location1=ca,ip1=2.2.2.2,hostname2=host2.example.com,location2=wa,ip2=3.3.3.3`

Am using request.GET I want to get the output in a tuple or hash form as:

expected data:

- Code:
`[{host1.example.com:[ca,2.2.2.2]},{host2.example.com:[wa,3.3.3.3]}]`

Please note that hostnames or ips can be in random order

eg: following is a valid URI

- Code:
`https://mydesktop.com/validator?hostname1=host1.example.com,location2=ca,ip2=2.2.2.2,hostname2=host2.example.com,location1=wa,ip1=3.3.3.3`

response in the above situation should be

- Code:
`[{host1.example.com:[wa,3.3.3.3]},{host2.example.com:[ca,2.2.2.2]}]`

Statistics: Posted by vedika9009 — Thu Mar 05, 2015 8:02 am

]]>

]]>

Thank you for that, I understand it is pretty difficult to pinpoint to the problem when the full scripts are not there but the main problem with these scripts is that there is realy no way to test them, except running them and see if it works.

And you can only run them if you have Ableton installed.

It works in cobination with the Ableton Live API which is not very well documented, so it's all trial and error.

It works like this; you write or modify the script and then open your music software, which will compyle the script if it works and otherwise it will just leave them as it is.

There is a log message though but when you make one mistake somewhere in most cases it will give you all kinds of random errors.

For example in this particular case I get these errors in my Log file:

Screen Shot 2015-03-05 at 08.25.56.png

Which point to system scripts that don't have mistakes in them.

As soon as I set the range num_tracks back to 8 they dissapear.

For any of you interrested, the full scripts are in the attatchements.

Thanks!

Jor

Statistics: Posted by Jorgalad — Thu Mar 05, 2015 7:32 am

]]>

All other characters, if preceded by a slash, will be treated like themselves, preceded by a slash. Just like any normal string. Only in the special combinations, the slash will be removed as an escape character.

See also: http://stackoverflow.com/questions/2179 ... ing-python

Statistics: Posted by Kebap — Thu Mar 05, 2015 7:14 am

]]>

V2.7.9

I know the \ is the escape character for printing and so for example to print a " you send \" and so on. Consequence of using the \ as escape is that to print a \ you need to send a \\. Specials like tabs are \t etc. No issue there.

But I found that to print the chracters \ and / back to back ie \/ you don't need to escape the \ but simply print \/. So this:

- Code:
`print "\/"`

... causes this to print:

\/

Interestingly though, if you do escape the \ in that case and go:

print "\\/"

... you get the right result:

\/

Seems the \/ combo is a special case since the \ doesn't need to be sent as \\?

If so, are there any others that one should know about?

Statistics: Posted by TwoSheds — Thu Mar 05, 2015 4:21 am

]]>

- Code:
`def ProHappy(n,nTrials):`

k = float(0)

for k in range(nTrials):

s=MakePath(n)

if isHappy(s,n):

k = float(k+1)

print k/nTrials

Statistics: Posted by thrgk — Thu Mar 05, 2015 2:31 am

]]>

- Code:
`#computes the probability of exiting by a corner tile`

def ProHappy(n,nTrials):

p=0

s=MakePath(n)

while p < nTrials:

if isHappy(s,n):

return p

p+=1

print float(p)

print float(p/nTrials)

The first problem is "s=MakePath(n)". It's outside the while loop, so every time through the while loop you are testing the same path. The "return p" statement is another problem. The return statement ends execution of the function, so as soon as you get your first happy robot, ProHappy is done. The "p += 1" statement is a third problem. It's outside of the code block for the conditional. So it will execute every trial, not just on the ones where the robot is happy. Your print statement at the end should probably be a return statement instead. However, if you are using Python 2, it won't work right. In that case you need to make one of the two a float before dividing, as in "return p/float(nTrials)".

Statistics: Posted by ichabod801 — Thu Mar 05, 2015 2:10 am

]]>

]]>

]]>

I seem to be having a problem, I am using a function isHappy(s,n), which determines if a robot going randomly on a graph is happy. Happy is considered when it exits via a corner tile. I then need to use isHappy in ProHappy to find the probability of a robot being happy in nTrials , with size n playpen.

Now I know "how" to do it, for each trial that is happy I need to add +1 to k, and then in the end /nTrials, however my code is not working correctly. For Proappy i check if isHappy is true, and if so, then add +1.

Any idea whats up with my code?

- Code:
`from random import randint as randi`

from simpleGraphicsE import *

def MakePath(n):

""" Returns a string s that consists of the characters

'E', 'N', 'W', and 'S'.

s[k] indicates how the robot moved during step k. Thus,

if s[7] is 'N', then in step 7 the robot moved North, i..e,

the y-value of its location was increased by 1.

PreC: n is a positive integer

"""

# The current location of the robot is (x,y)

x = 0

y = 0

# The travel string s will be built through repeated concatenation

s =''

steps=0

maxSteps=10000

while abs(x)<=n and abs(y)<=n and steps<maxSteps:

i = randi(1,4)

if i==1:

# Move east

x=x+1

s =s+'E'

elif i==2:

# Move north

y=y+1

s=s+'N'

elif i==3:

# Movewest

x=x-1

s=s+'W'

else:

# Move south

y=y-1

s=s+'S'

DrawDisk(x,y,.25,color=RED)

return (s)

"""As n increases the average gets larger and larger, n=3 gave me avg 18,

while n=1 gave me avg of 3, and n=20 gave me 507 and n=10 gave me 139, so we can see with a small increase

in n, the average hops it takes starts to go very large"""

def HopsAve(n,nTrials):

#set totalsteps to 0

totalSteps = float(0)

for k in range(nTrials):

#get the return from MakePath

path = MakePath(n)

#for each trial we add totalsteps and then the len(path(s)) whuch

#gives in essense s is the number of hops

totalSteps = float(totalSteps + len(path))

return float(totalSteps)/nTrials

#checks to see if the robot exited through a corner tile

def isHappy(s,n):

#gets s and counts the # of E's,S's,N's, W's

s=MakePath(n)

E=s.count('E')

S=s.count('S')

W=s.count('W')

N=s.count('N')

#should be N - S and E-W

Yf=N-S

# and E - W

Xf=E-W

#check for all 4 corners

if abs(Yf) == (n-1) and abs(Xf) == (n-1):

return True

else:

return

#computes the probability of exiting by a corner tile

def ProHappy(n,nTrials):

p=0

s=MakePath(n)

while p < nTrials:

if isHappy(s,n):

return p

p+=1

print float(p)

print float(p/nTrials)

"""The probability of a robot being happy we were told is 4*(1/8n) which is 1/2n which is equal to

the comparison p=1/2n. So whatever we have set for n we just stick into n's place and we get the

probability. If we set n=5 we get 1/2n =.1 which is the same as p=1/2n=.1. Our answer will always

be equal to p's answer also"""

#Determins if the robot is homesick(edge distance < Homedistance)

def isHomesick(x,y,n):

#determines the edgedistance by taking the min of n-abs(x) and n-abs(y)

edgedistance = min(n-abs(x),n-abs(y))

#determines homedistance by adding abs(y+x)

homedistance=abs(y)+abs(x)

#if edgedistance < homedistance then returns true

if edgedistance<homedistance:

return True

else:

return False

#continously checks to see at what point the robot becomes homesick

def Homesick(s,n):

#idea is to go through the loop and keep checking x and y to see when edist < hmdist

#let initial x,y be 0

x = 0

y = 0

#lets iterate through the path string s

#while loop

k = 0

while k<len(s):

#s[k] is the kth character in s

#now update the values of x and y depedning on s[k]

if s[k] == 'N':

y = y + 1

elif s[k] == 'S':

y = y -1

elif s[k] == 'E':

x = x + 1

elif s[k] == 'W':

x = x - 1

#check if current location is homesick

# if yes, return the current hop, k

# we can check also as isHomesick(x,y,n) == True

if isHomesick(x,y,n):

return k

#increment hop

k = k + 1

return k

#computes an average based on n of when the robot will become homisck

def HomesickAve(n,nTrials):

#makes hmsickave to a float of 0

hmsickave=float(0)

for p in range (nTrials):

#for loop that sums # of hops and divides by nTrials

s=MakePath(n)

print s

route=float(Homesick(s,n))

hmsickave = float(hmsickave + route)

#must print as a float

return hmsickave/float(nTrials)

"""As n gets larger, the average number of hops for the robot to become homesick increases, in my testing

when n=5, the avg was 8.222, n=10 the avg was 24.05, n=20 avg was 94.69, and when n=25 the avg was 144.61,

this only makes since because as n gets bigger, (the playpen gets bigger) it will take more steps to become

homesick, since being homesick is when you are closer to the edge then home(0,0)"""

def DrawPlaypen(n):

""" Draws a size n playpen.

n should be <=10 for the labels to be clear

PreC: n is a positive int.

"""

# Draw the pen and its purple boundary

DrawRect(0,0,2*n+3,2*n+3,color=PURPLE,stroke=0)

DrawRect(0,0,2*n+1,2*n+1,color=YELLOW,stroke=0)

x = -n-.5

y = -n-.5

# Add in the vertical and horizontal grid lines.

for k in range(2*n+2):

DrawLineSeg(x,-n-1.5,2*n+3,90)

DrawLineSeg(-n-1.5,y,2*n+3,0)

x+=1

y+=1

# Application Script

if __name__ == '__main__':

ProHappy(5,10)

Statistics: Posted by thrgk — Thu Mar 05, 2015 12:41 am

]]>

Are you having a problem, or just don't understand the process?

Statistics: Posted by Mekire — Thu Mar 05, 2015 12:41 am

]]>

- Code:
`def blackAndWhite(image):`

blackPixel=(0,0,0)

whitePixel=(255,255,255)

for y in xrange(image.getHeight()):

for x in xrange(image.getWidth()):

(r,g,b)=image.getPixel(x,y)

average=(r+g+b)/3

if average <128:

image.setPixel(x,y,blackPixel)

else:

image.setPixrl(x,y,whitePixel)

Statistics: Posted by whoovian11 — Thu Mar 05, 2015 12:17 am

]]>

Statistics: Posted by micseydel — Wed Mar 04, 2015 10:19 pm

]]>

And I want to ask a question about the Python.

Well, when I create a .py file and I want to open it, it opens up and running perfectly. But it opens a short open and then closes itself quickly.

Here is an illustrative picture:

I hope that question will be responded.

Best regards,

THEMUD.

Statistics: Posted by THEMUD — Wed Mar 04, 2015 10:14 pm

]]>

]]>