So when we assign a value to a variable then that variable should be able to hold it, right? and if not compiler produces the error. Now there is an option in C# known as Checked (which is by default) and unchecked option. But is there practical use of unchecked? any comments for a layman? :)
Example:
int a=int.MaxValue;
int b=int.MaxValue;
unchecked
{
int sum=a+b;
}
I have a Python function accepting several string arguments def foo(a, b, c): and concatenating them in a string.
I want to iterate over all function arguments to check they are not None. How it can be done?
Is there a quick way to convert None to ""?
Thanks.
I have a text file containing data in rows and columns (~17000 rows in total). Each column is a uniform number of characters long, with the 'unused' characters filled in by spaces. For example, the first column is 11 characters long, but the last four characters in that column are always spaces (so that it appears to be a nice column when viewed with a text editor). Sometimes it's more than four if the entry is less than 7 characters.
The columns are not otherwise separated by commas, tabs, or spaces. They are also not all the same number of characters (the first two are 11, the next two are 8 and the last one is 5 - but again, some are spaces).
What I want to do is import the entires (which are numbers) in the last two columns if the second column contains the string 'OW' somewhere in it. Any help would be greatly appreciated.
I have four tables
Tag=id,tag_name
Image=Id,Image_name
TagImage=Id,tag_id,Image_id
ImageStudent=id,Image_id,student_id
And I want to find a record using student id and tag name. What relationship do I use?
We had a talk with colleagues about databases yesterday as we will have a DB2 education in few weeks. I'm wondering, what are the differences between DB2 and Oracle as two major enterprise solutions? Are there any limitations in comparison to each other? Are there any tasks more suitable for DB2 or Oracle?
(I found this article, but I somehow doubt it covers everything)
I have this code:
a=[['a','b','c'],['a','f','c'],['a','c','d']]
for x in a:
for y in x:
if 'a' in x:
x.replace('a','*')`
but the result is:
a=[['a','b','c'],['a','f','c'],['a','c','d']]
and bot a=[['b','c'],['f','c'],['c','d']]
What should I do so the changes will last?
I am new to programming and come from a non-CS background (no formal degree). I mostly program winforms using C#.
I am confused about 32 bit and 64 bit.... I mean, have heard about 32 bit OS, 32 bit processor and based on which a program can have maximum memory. How it affects the speed of a program. There are lot more questions which keep coming to mind.
I tried to go through some Computer Organization and Architecture books. But, either I am too dumb to understand what is written in there or the writers assume that the reader has some CS background.
Can someone explain me these things in a plain simple English or point me to something which does that.
EDIT: I have read things like In 32-bit mode, they can access up to 4GB memory; in 64-bit mode, they can access much much more....I want to know WHY to all such things.
BOUNTY: Answers below are really good....esp one by Martin. But, I am looking at a thorough explanation, but in plain simple English.
Hi there
I use concatenate to pull data together from different cells in my spreadsheet. Since my data changes daily, I want the formula to also change daily without having to manually input the new cell in the concatenate formula. I am looking for a way to do this but not sure how. Can anyone out there help me out please!? I appreciate the assistance in advance!
I've been a Software Developer now for over 10 years. I've mostly worked in Embedded C with some time spent on C++ (limited) and Java.
I'm looking to learn some new technologies and skills. I thought that database programming may be interesting to learn. I would like to make my own pet project in order to learn these things.
My platform of choice is Windows but can work in Linux also.
My ideal pet project would involve a GUI and some network/internet programming also which I have some experience doing.
I wouldn't mind getting into C# but don't want to bite off more than I can chew right now as my spare time is limited.
If I understand correctly SQLite allows for programs to use a database without running an ODBC server. Is this correct? Is that a good place to start?
What can I do to start that is not too complicated but not so simple that I won't learn the details also?
Your opinions and feedback would be appreciated.
When thinking in a functional mindset, given that functions are supposed to be pure, one can conclude any function with no arguments is basically just a value.
However, reallity gets in the way, and with different inputs, I might not need a certain function, and if that function is computationally expensive, I'd like to not evaluate it if it's not needed.
I found a workaround, using let func _ = ... and calling it with func 1 or whatever, but that feels very non-idiomatic and confusing to the reader.
This boils down to one question: In F#, Is there a proper way to declare a function with zero arguments, without having it evaluated on declaration?
Hello, everyone!
I am implementing a text-based version of Scrabble for a college project.
I have a vector containing around 400K strings (my dictionary), and, at some point in every turn, I'm going to have to check if any word in the dictionary can be formed with the pieces in the player's hand.
My only solution to this is iterating through the string, one by one, and using a sub-routine I have to check if the string in question can be formed from the player's pieces. I'll implement a quickfail checking if the user has any vowels, but it'll still be woefully inefficient.
Any suggestions?
Thanks for your time!
Hi all,
We have a process which takes a very large csv (1.6GB) and breaks it down into pieces (in this case 3). This runs nightly and normally doesn't give us any problems. When it ran last night, however, the first of the output files had lost precision on the numeric fields in the data. The active ingredient in the script are the lines:
while lineCounter <= chunk:
oOutFile.write(oInFile.readline())
lineCounter = lineCounter + 1
and the normal output might be something like
StringField1; StringField2; StringField3; StringField4; 1000000; StringField5; 0.000054454
etc.
On this one occasion and in this one output file the numeric fields were all output with 6 zeros at the end i.e.
StringField1; StringField2; StringField3; StringField4; 1000000.000000; StringField5; 0.000000
We are using Python v2.6 (and don't want to upgrade unless we really have to) but we can't afford to lose this data. Does anyone have any idea why this might have happened? If the readline is doing some kind of implicit conversion is there a way to do a binary read, because we really just want this data to pass through untouched?
It is very wierd to us that this only affected one of the output files generated by the same script, and when it was rerun the output was as expected.
thanks
Jack
I am writing a python package. I am using the concept of plugins - where each plugin is a specialization of a Worker class. Each plugin is written as a module (script?) and spawned in a separate process.
Because of the base commonality between the plugins (e.g. all extend a base class 'Worker'), The plugin module generally looks like this:
import commonfuncs
def do_work(data):
# do customised work for the plugin
print 'child1 does work with %s' % data
In C/C++, we have include guards, which prevent a header from being included more than once.
Do I need something like that in Python, and if yes, how may I make sure that commonfuncs is not 'included' more than once?
Hello,
When sending data from a form to a second page, the value of the session is always with the name "Array" insteed of the expected number.
The data should get displayed in a table, but insteed of example 1, 2, 3 , 4 i get : Array, Array, Array.
(A 2-Dimensional Table is used)
Is the following code below a proper way to "call" upon the stored values on the 2nd page from the array ?
$test1 = $_SESSION["table"][0];
$test2 = $_SESSION["table"][1];
$test3 = $_SESSION["table"][2];
$test4 = $_SESSION["table"][3];
$test5 = $_SESSION["table"][4];
What exactly is this, and how can i fix this?
Is it some sort of override that needs to happen?
Best Regards.
I'm using Drupal 6. Typically, when the user requests a URL for which Drupal has no response, it uses index.php as the error document. However, I'd like to suspend this behavior for a specific URL. How can I do this?
RewriteCond %{REQUEST_FILENAME} !=fail
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Where "fail" is the path I want to block. So www.example.com/fail should result in a 404.
Incidentally, what does [L, QSA] do? I've looked at documentation without luck.
Hello,
I am trying to perform some calculations with a form but every time i try to work with checkboxes it goes wrong.
The checkboxes are beign set on value 1 in the form itselff and are being checked if there checked or not.
$verdieping = isset($_POST["verdieping"]) ? $_POST["verdieping"] : 0;
$telefoon = isset($_POST["telefoon"]) ? $_POST["telefoon"] : 0;
$netwerk = isset($_POST["netwerk"]) ? $_POST["netwerk"] : 0;
When i try to do calculations every works expect for the options with the checkboxes.
When both checkboxes (telefoon & netwerk) are selected the value should be 30.
If only one is selected the value should be 20.
But no mather what i have tried to write down it always give problem, and it always uses 20, never the value 30.
How do i solve this problem? Or suppose i am writing the syntax all wrong to lay conditions to a calculation? Any input appreciated.
$standnaam = $_SESSION["standnaam"];
$oppervlakte = $_SESSION["oppervlakte"];
$verdieping = $_SESSION["verdieping"];
$telefoon = $_SESSION["telefoon"];
$netwerk = $_SESSION["netwerk"];
if ($oppervlakte <= 10)
$tarief = 100;
if ($oppervlakte > 10 && $oppervlakte <= 20)
$tarief = 90;
if ($oppervlakte > 20)
$tarief = 80;
if($verdieping == 1)
{
$prijsVerdieping = $oppervlakte * 120;
}
else
{
$prijsVerdieping = 0;
}
if(($telefoon == 1) && ($netwerk == 1))
{
$prijsCom = 30; // never get this value, it always uses 20
}
if(($telefoon == 1) || ($netwerk == 1))
{
$prijsCom = 20;
}
$prijsOpp = $tarief * $oppervlakte; // works
$totalePrijs = $prijsOpp + $prijsVerdieping + $prijsCom; //prijsCom value is always wrong
Regards.
I'm wondering specifically what experienced programmers thought when they started developing in Python. I'm sure the answer depends on your background, but my own personal answer is the conversion of basically anything in the language to a True/False value in boolean contexts.
Resulting in "oddities" like:
if x:
not meaning the same thing as:
if x == True:
I understand why, but it bugs me, and I certainly had to think about it a bit when I first ran into it.
Hi, I am new to python.
I am trying to extract the text between that has specific text file:
----
data1
data1
data1
extractme
----
data2
data2
data2
----
data3
data3
extractme
----
and then dump it to text file so that
----
data1
data1
data1
extractme
---
data3
data3
extractme
---
Thanks for the help.
Hi,
I was using Sonar to make my code cleaner, and it pointed that I'm using new Integer(1) instead of Integer.valueOf(1). Because it seems that valueOf does not instantiate a new object so is more memory-friendly. How can valueOf not instantiate a new object ? How does it work ? Is this true for all integers ?
thanks.
I am trying to remove the last <li> element from a <ul> element only if it exceeds a particular length. For this, I am doing something like this:
var selector = "#ulelement"
if($(selector).children().length > threshold) {
$(selector + " >:last").remove();
}
I don't like the fact that I have to use the selector twice. Is there a shorter way to do this? Something like a "remove-if-length-greater-than-threshold" idea. I was thinking that maybe there is a way to do this using the live() function but I have no idea how.
I'd like to write a simple decorator that I can put above functions in my controller to check authentication and re-direct to the login page if the current user is not authenticated. What is the best way to do this? Where should the decorator go? How should I pass cookie info to the decorator? Sample code is greatly appreciated.
Thank you!