Getting Python scripts to execute in RedHat
I apologise if this is a stupid newbie error, but I've been googling "hash bang" and "shebang" all morning. I've added the shebang to my scripts: #!/usr/bin/python I've added execute permissions: chmod +rx shebang.py But I still can't execute my scripts by themselves shebang.py ## produces error python shebang.py ## runs correctly I found one site that mentioned adding "./" to the beginning, and that works. ./shebang.py ## runs correctly. I gather that there's a path problem then. My script is in ~/pyscripts/. How do I get my scripts to run without using "./"? -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting Python scripts to execute in RedHat
Dennis Lee Bieber wrote: > Now, if you mean you store all your python programs in > "~/pyscripts/" but you want them to run from any directory, you need to > add "~/pyscripts/" to your login PATH definition. If you want to always > make the local directory valid, add the "./". Thank You. Between your explanation and the previous poster's instruction, I've got it. -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you use pickle?
John Salerno wrote: > I'm sorry, but I'm terribly confused. Nothing seems to be working for > me. I *think* what I need to pickle is an image file, SNIP Hint: Read the source for that page more carefully. -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you use pickle?
John Salerno wrote: > Pythor wrote: > > John Salerno wrote: > > > >> I'm sorry, but I'm terribly confused. Nothing seems to be working for > >> me. I *think* what I need to pickle is an image file, > > > > SNIP > > > > Hint: Read the source for that page more carefully. > > > > Hmmm...the source doesn't say much. Is there more to do with the source > beyond using it to figure out what 'peak hell' means? Yes... It mentions a whole different file, which you need to use pickle on. -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you use pickle?
John Salerno wrote: > Pythor wrote: > > John Salerno wrote: > >> Pythor wrote: > >>> John Salerno wrote: > >>> > >>>> I'm sorry, but I'm terribly confused. Nothing seems to be working for > >>>> me. I *think* what I need to pickle is an image file, > >>> SNIP > >>> > >>> Hint: Read the source for that page more carefully. > >>> > >> Hmmm...the source doesn't say much. Is there more to do with the source > >> beyond using it to figure out what 'peak hell' means? > > > > Yes... It mentions a whole different file, which you need to use pickle > > on. > > > > Yikes, I even took a second look at that after you said re-read the > source and then I ignored it! Thanks! Whis is why I said carefully ;) I missed it several times myself when I was working on the challenge. -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you use pickle?
John Salerno wrote: > John Salerno wrote: > > Pythor wrote: > > > >> Whis is why I said carefully ;) I missed it several times myself when > >> I was working on the challenge. > > > > Ok, frustration has set in again. I see the file name in the source > > code, but am I meant to actually access a file, or just use the name > > itself? I also had to look up what 'banner' meant in Unix, which wasn't > > a very fun thing to have to do for a Python puzzle. > > Ah, I should have known we weren't done with URL manipulation yet. Now I > just need to figure out what to do with this source code. Incidentally, there's a forum specifically for posting an receiving hints on the challenges here: http://www.pythonchallenge.com/forums/viewforum.php?f=1 Not that I mind helping. ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you use pickle?
John Salerno wrote: > Pythor wrote: > > John Salerno wrote: > >> John Salerno wrote: > >>> Pythor wrote: > >>> > >>>> Whis is why I said carefully ;) I missed it several times myself when > >>>> I was working on the challenge. > >>> Ok, frustration has set in again. I see the file name in the source > >>> code, but am I meant to actually access a file, or just use the name > >>> itself? I also had to look up what 'banner' meant in Unix, which wasn't > >>> a very fun thing to have to do for a Python puzzle. > >> Ah, I should have known we weren't done with URL manipulation yet. Now I > >> just need to figure out what to do with this source code. > > > > Incidentally, there's a forum specifically for posting an receiving > > hints on the challenges here: > > > > http://www.pythonchallenge.com/forums/viewforum.php?f=1 > > > > Not that I mind helping. ;) > > > > Yeah, I read the whole thread for this level and even posted a question, > but the forums are pretty dead. Not only that, but I'm starting to get > the feeling that these challenges are going to require a little more > programming expertise than I have, because all of the 'hints' are still > too vague for me. > > Like I said in my post on the hints forum, I really enjoy figuring out > how to use Python to solve the puzzles, but it's not very fun when I > don't know *what* to do in the first place, and I think knowing what to > do has a lot to do with how experienced you are with certain CS subjects > and how quickly you can identify the problem and a possible solution. > All I see is huge bunch of string characters with no idea what to do > with it to extract any kind of information. Only a bunch of string characters? If that's true, you missed something. I get a bunch of lists of tuples. Each tuple has a meaning associated with the original filename, and an old unix command. Which is what confused the heck out of me the first time, not knowing much Unix. The command is used to make large signs using old-style dot matrix printers.If you want a more coherent hint than that, email me at pythor @ pythor dot com -- http://mail.python.org/mailman/listinfo/python-list
More pythonic circle?
I wrote the following code for a personal project. I need a function that will plot a filled circle in a two dimensional array. I found Bresenham's algorithm, and produced this code. Please tell me there's a better way to do this. import numpy def circle(field=None,radius,center=(0,0),value=255,): '''Returns a list of points within 'radius' distance from point 'center'.''' if field==None: field=numpy.zeros((radius,radius),'u') cx,cy=center filllist=[] dy,dx=0,radius r2=radius**2 while dy<=(radius*.71): # sin of 45 degrees if dx**2+dy**2<=r2: for x in range(dx): filllist.append((x,dy)) dy+=1 else: dx-=1 if dxhttp://mail.python.org/mailman/listinfo/python-list
Re: More pythonic circle?
John Machin wrote: > OTTOMH, in a rush to go out: never mind Pythonic, following apply to > any language: > (1) accuracy: (a) sue me if I'm wrong, but I think you need range(dx+1) > so that the dx pixel is filled in Hmm. I think you're right. Thanks. > (b) a few more digits after 0.71 > might be useful Sine of 45 degrees is actually .707... I rounded up, since I was using <=. Figured that would make it clear. > (2) efficiency: seems that range(dy, dx+1) would save some wear & tear > on the circuitry :-) It took me a few minutes to figure out waht you meant here. This will certainly help reduce the repeated coordinates. Thanks, again. > (3) legibility: there's no prize for the script with the absolutely > minimum number of space characters :-) True. I assume your saying I should make cx,cy,dx, and dy better names. I probably will. Up to now I was just playing around with this, and not really expecting anyone else to read it. > I think I've got an article on better Bresenham somewhere in the > archives; will dig it out later. I'd definitely appreciate it. In fact, I'm trying to find a decent sphere version, and getting nowhere with google. I tried to figure it out on my own, and ended up with 48 coordinates for each valid test. I'm not sure if that's right. Lee -- http://mail.python.org/mailman/listinfo/python-list
Re: More pythonic circle?
Michael Tobis wrote: > Proving yet again that it's possible to write Fortran in any language. > Ouch... > You aren't getting any benefit from numpy or python here. Are you > aiming for speed or legibility? > Speed will be a necessity, eventually. I was just really aiming for something that works, and that I am capable of writing. > Also, with this code, you are using radius for the dimensions of the > enclosing box, as well as the radius of the circle, so it's guaranteed > to not to actually produce a whole circle. Recall what python does with > negative indices! > I'm not sure what you mean here. It produces an eighth-circle, and then plots each point in the 8 symmetrical positions on the circle. Except for the (dx+1) point made above, what piece of the circle is missing? > I'll bet this does the trick for you and runs faster than what you've > got > > def circle(rad = 5,max_x = 20, max_y = 20,cx = 10, cy= 10, value=255): >radsq = rad * rad >return numpy.array([[((x - cx) ** 2 + (y - cy) ** 2 < radsq) and > value or 0 for x in range(max_x)] for y in range(max_y)],'u') > > I think the pure numpy solution should be something like (untested) > > def circle(rad = 5,max_x = 20, max_y = 20,cx = 10, cy= 10, value=255): >def sqdist(x,y): > return (x - cx) * (x - cx) + (y - cy) * (y - cy) >distarray = numpy.fromfunction(sqdist,(max_y,max_x)) >return > numpy.asarray(numpy.choose(greater(distarray,rad*rad),(0,value),'u') > I'll take a look at both of these. At this point, I can't quite wrap my head around what you're doing for either one. > Neither approach will get you the eightfold speedup that the messy code > was aimed at, but in practice they will spend less time at the > interpreter level and will likely run faster. > > mt -- http://mail.python.org/mailman/listinfo/python-list
Re: More pythonic circle?
Steven D'Aprano wrote: > No, "minimum number of space characters" means "you don't use enough > spaces", not "your variable names are too short" *wink* > Hmm. Guess I can't read too well. > Within a single line, a good guideline is to leave a single space on > either side of pluses and minuses (e.g. x**2 + 5*x - 3). Likewise, a > single space on both sides of an equal sign and a single space after > commas tend to be usual. What I produced was natural for my fingers, but I can see that it's difficult on the eyes. I'll try to remember that. > > As for variables cx, cy, dx and dy, I don't believe that they are unclear. > If your function is highly mathematical in nature, I believe it is > acceptable if not expected to follow standard mathematical conventions > such as r for radius, x and y for real numbers, z for complex, dx for > delta (change of) x, etc. If in doubt, when initialising the variable add > a comment spelling it out in full. > > On the other hand, you do have an argument "value" with default 255, with > not even hint for what it is. Well, value is just a value. It's the number that get's punched into the array for any points within the circle. I didn't have any better name I could think of. -- http://mail.python.org/mailman/listinfo/python-list
Re: More pythonic circle?
Fredrik Lundh wrote: > "Pythor" wrote: > > > > You aren't getting any benefit from numpy or python here. Are you > > > aiming for speed or legibility? > > > > > Speed will be a necessity, eventually. I was just really aiming for > > something that works, and that I am capable of writing. > > any special reason you cannot use an existing graphics library ? > > Well, I'm not really interested in pretty pictures, but in the resulting array. It might be worth using a graphics library and then converting from an image to an array when I'm done. I've been playing with PIL for that. But I wanted to see what I could do on my own, too. In addition, I'll eventually need some functions that are definitely not in a standard graphics library, and I wanted to get started with something I thought was relatively simple. -- http://mail.python.org/mailman/listinfo/python-list
Re: More pythonic circle?
John Machin wrote: > [Michael Tobis] > Also, with this code, you are using radius for the dimensions of the > enclosing box, as well as the radius of the circle, so it's guaranteed > to not to actually produce a whole circle. Recall what python does with > negative indices! > > [Pythor] > I'm not sure what you mean here. It produces an eighth-circle, and > then plots each point in the 8 symmetrical positions on the circle. > Except for the (dx+1) point made above, what piece of the circle is > missing? > == > What Michael means is that for example a circle of radius 5 is 11 > pixels wide and 11 pixels high. You are trying to cram it into a box of > 5 x 5 pixels [or maybe 6x6 (I'm numpy-challenged)]. The result will > resemble a train smash. Have you considered *TESTING* your code? It's > not very difficult at all to draw the expected results for radii of > about 4 or 5 pixels on the back of an envelope ... > Sure, I tested it. And it works, for the most part. I did miss those the dx+1 points, which John pointed out. On the other hand, I'm not having any trouble producing a whole circle, while you seem to think I'm only producing half a circle. The code that limits itself to a 5x5 box is only expected to produce an eighth of the circle. The actual assignment portion uses reflection to plot points in the whole area. If there's some other problem with it, I haven't noticed. > By the way, there are signs of a benchmark war breaking out. What are > typical sizes you would be using in practice for the radius and the > enclosing box? > Well, I'm not really asking someone else to write my code for me, but here goes. The desire is to have an array of about 1000 X 1000, bigger would be better. I want to fill this array with regions of values, with each region being between .5% and 5% of the total area. I'm using random circular regions placed around the array, allowing new regions to overlap old ones. So, I'm using circles of roughly 5 to 50 radius, and throwing a few thousand into the array. Actually, this is a prelude to trying the same thing with spheres in a 3-dimensional array, but a 1000X1000x1000 array is larger than my memory can handle. -- http://mail.python.org/mailman/listinfo/python-list
