I'm just getting started in Python, and came across your response to the "Palindrome" problem whilst browsing the forum to pick up tips.
It's a really elegant compact solution - I wish I could write code like that! - but there seems to be a heck of a lot of stuff going on in that one short line, and as a newbie I confess that I don't fully understand the syntax.
I know it is using string slicing, but haven't seen a string slicing command take 3 parameters before, and also be part of a conditional Boolean statement in the same line of code.
It would really help my understanding if you could describe exactly how your statement does its magic!
Been playing with string slicing... think I get it now...
I didn't realise that you could specify a third parameter for string slicing.
In fact the syntax for string slicing parameters seems very similar to that used in the "range" function - i.e. "[start:stop:step]".
So [:] means "include characters starting from character index 0 (i.e. start from the very first character) and end at the character at index (end-1) (i.e. finish at the last character) - i.e. "take the whole string"
...and [::-1] means "take the whole string of characters, but read it starting from the end and stepping backwards one character at a time"
So if the string equals itself written backwards, Boolean s == s[::-1] is True, and isPalindrome returns "True"
If the string is not equal to itself written backwards, Boolean s == s[::-1] is False, and isPalindrome returns "False".
I have a device(mote) that monitor temperature, light and sound. It transmit the data to PC using wireless and store in a database (PostgreSQL). After storing the data, i have it exported out becoming a .sql extenstion file. I will be only able to view the data via a program provided by the device company.
The main aim of my project is to make data viewable on html where im able to publish it online.
Where i will be using the output data (.sql file) and publish it on html using PERL and CGI.
Any helps on how i can make the .sql file readable in PERL or do i need another program to read the database output(.sql file) then making PERL script able to read the filen and then publish it online?
The device I'm using which is made by Xbow and im running Win XP.
So, a while ago I wrote here about starting to experiment with Django, and now I have come to a stop...
I usually map my Django projects on the root, but this time I tried something different and failed very badly...
I tried to map it to http://foo.com/django and encountered two problems, I hope you guys can help me with...
If I go to address http://foo.com/django (without trailing slash) I get an Internal Server Error.
Log shows this info:
File "/var/lib/python-support/python2.5/django/middleware/common.py", line 41, in process_request
if settings.APPEND_SLASH and (old_url1-1 != '/') and ('.' not in old_url1.split('/')-1):
IndexError: string index out of range
If I include the trailing slash it works (at least it seems to).
APPEND_SLASH is (obviously) set to True.
Let's go with urls.py that looks like this:
from django.conf.urls.defaults import *
from djangobook.views import hello
urlpatterns = patterns('',
Instead of going to http://foo.com/django/hello I get redirected to http://foo.com/hello. I presume I'm missing a setting or something to make it relative to the project's starting URL?
We are using Linux daily to UP our productivity - so UP yours!
You shouldn't need to make any mod_wsgi changes. And don't copy the apache config on the link, it looks like it would kill you app since it seems to be a mod_python set-up. So, try to leave you apache config alone and start with your patterns.
And above all things, never think that you're not good enough yourself. A man should never think that. My belief is that in life people will take you at your own reckoning. --Isaac Asimov
Avoid the crowd. Do your own thinking independently. Be the chess player, not the chess piece. --Ralph Charell
Ok, so what I just figured is that I get redirected from foo.com/django/hello to coo.com/hello only if I leave the trailing slash.
How can I make django append the trailing slash in the URL? APPEND_SLASH is set to true.
We are using Linux daily to UP our productivity - so UP yours!
Well I am not sure but according to OS fundamentals these things should be possible,
1) Rename and delete of directory not allowed
2) Rename and delete (and editing) is not allowed for the file getting processed in current loop instance
3) One should be able to rename or delete or editing a file which is not getting processed in current loop instance
4) One should be able to add new file in that directory.
These all are theoretically, one can omit or change these rules for his OS. And sorry I haven't tried the situation you gave. But I think it should be possible. And it might led to infinite loop.
As per the mutual exclusion fundamental no mater what you are doing (read/write) with data (in this case reading file name) you cannot change that name.
Ya but you might have seen in windows or unix or linux that in if you have opened one folder at two differ location and you add one file/folder at one place changes get reflected to another place. I am not so sure about windows directroy structure in detail. But for unix I know that once you add new file in directory its inode will be added to director file structure list and those changes can be read using directory structure. I dont know whether I am able to clarify your doubt or not. It will be better if you find out such script is working on your system and if it is not working then try to run such script and check. In both case please let me know the result I would like to know whether it is possible or not.
hello guys, i have a problem with a query.
I have a table actions which has no primary key. any one particular record can be identified by the combination of actionID, taskID and ProjectID which are the other fields in actions table.
Here is an example of the possible situations of entries in the actions table(so that you get an idea of what i am talking about)
ActionID 1 for taskID 1 of ProjectID 10-000
ActionID 2 for taskID 1 of ProjectID 10-000
ActionID 1 for taskID 2 of ProjectID 10-000
ActionID 1 for taskID 2 of ProjectID 10-001
ActionID 2 for taskID 2 of ProjectID 10-001
ActionID 3 for taskID 1 of ProjectID 10-000
ActionID 1 for taskID 1 of ProjectID 10-002
ActionID 1 for taskID 2 of ProjectID 10-003
When i am creating a new action for taskID 1 of ProjectID 10-000, then what i am doing is i am scanning the all the ActionIDs of the taskID 1 of ProjectID 10-000, ordered by ActionID and incrementing the last obtained ActionID by 1 to generate a new ActionID for the new action.
Now suppose the entries of ActionID for taskID 1 of ProjectID 10-000 in the database are 1,2,5,6,8,10,15,16, then according to my logic, the newly generated ActionID would be 17, but that is not what i want. I want the newly generated ActionID to be 3, because 3 is not present in the ActionID field of taskID 1 of ProjectID 10-000 combination .
In the above example, if i delete ActionID 2 for taskID 1 of ProjectID 10-000 and then when a new action is added to the same combination of taskID and ProjectID, i want the newly generated ActionID to be 2 and not 4 which is what i am getting from my logic.
I used PEAR library to facilitate the export to am excel sheet, but what i got in my Excel sheet are below unrecognized characters (also include some codes), it supposed to be a table of data for several columns (ex. OS, Port Number, Comment, etc.). does anyone have the same issue before? What might be the cause of it? Many thanks...
Hello everyone, I am a newbie to php. I have been learning it and it is going well.
I have a php webpage, where there are textforms, dropdown list and stuff. There is Activity field in the database. Whatever activities that i do on the webpage, like modifying the text in the textbox, or changing a value for a dropdown list, these need to be automatically entered into the activity text in the database. Like this it happens only for one page.
Like for example, if i change a project name field and change status to 'Important' from 'Normal', then it needs to make an entry into the Activity field like:
On date:yyyy/mm/dd Project name has been changed to 'New Project' and status has been changed to 'Important'.
I think this can be achieved with stored procedures or i might be wrong.
I would really appreciate if someone could write down a sample code for me regarding this.
I want it to be doing automatically, like there are many other textboxes and dropdown lists in the page and i do not which one the user will be modifying so i cannot right one query for all of them. That is why i thought a stored procedure will be useful.