syntax

Ruby To Python Syntax Confusion

I'm trying to convert someone's Ruby code into my Python code. The originally developer is no longer with us and I don't know Ruby. Most of his code is easy enough to follow, but some of the following syntax is tripping me up. Example: myTable = '' myTable << [ 0, 1, 0, 0, 0, 300].pack('vvvvvv') ...

a basic question about "while true"

level: beginner def play_game(word_list): hand = deal_hand(HAND_SIZE) # random init while True: cmd = raw_input('Enter n to deal a new hand, r to replay the last hand, or e to end game: ') if cmd == 'n': hand = deal_hand(HAND_SIZE) play_hand(hand.copy(), word_list) print ...

C++ syntax question

Hello, I'm very new to c++, please help me to figure out how these operators work class MyCalss : public State // MyClass inherits State? { private MyClass(){} // Constructor for MyClass? MyClass(const MyClass&); // const means that invoking object will be not changed? What the meaning of '&' symbol? MyClass& MyClass& operator = (con...

Understanding python variable scope within class

I am trying to define a variable in a class that then can be accessed/changed from functions within that class. For example: class MyFunctions(): def __init__( self): self.listOfItems = [] def displayList( self): """Prints all items in listOfItems)""" for item in self.listOfItems: print item...

Need help to understand the usage of ":" in JavaScript

I'm using jQuery validate plugin, and when I met the following script, i recognize, that i don't understand many things in jQuery:) Look please $("#invitationform").validate({ rules: { phone: List item { required: true, minlength: 6, number:true } ...

Python: What does the use of [] mean here?

What is the difference in these two statements in python? var = foo.bar and var = [foo.bar] I think it is making var into a list containing foo.bar but I am unsure. Also if this is the behavior and foo.bar is already a list what do you get in each case? For example: if foo.bar = [1, 2] would I get this? var = foo.bar #[1, 2] a...

Python: Advanced Nested List Comprehension Syntax

I was playing around with list comprehensions to get a better understanding of them and I ran into some unexpected output that I am not able to explain. I haven't found this question asked before, but if it /is/ a repeat question, I apologize. I was essentially trying to write a generator which generated generators. A simple generator t...

PHP IF Statement executing both conditions

Hi, I'm currently integrating a payment system into my website. I have a response script which basically takes in the data from the secure server and displays to the customer if the payment has gone through or not. My problem is that the if statement is actually displaying both messages to the customer, even if the payment has been suc...

learning python - point to keep in mind w.r.t idioms!

I've been an avid learner of the Python language for quite some time. Having more than 6 years of Java[professional] experience, coupled with a bit of C++ [hobby] experience - it's fair to say my perspective is deeply entrenched in the idioms brought forth by such statically typed, strongly bound languages. In short - i could say the old...

What Vim script you recommend for checking Python syntax on the fly ?

I have visited Vim website , script section and found several synthax checkers for python. But which one to choose ? I would prefer something that supports python 3 as well, even though I code in python 2.6 currently. Do all these checkers need a module like pychecker and pyflakes ? I could install the most popular from scripts datab...

Loop thru a directory and seach in all pre-filtered XML files for a word

Hello everyone, I would like to loop thru a given directory and seach in all pre-filtered files for a search word. I prepared this code, but it is not looping thru all files, only the last file which was found is analyzed. Ideally all files should be analyzed and the output should be saved in a textfile. Could someone help? Thank you in...

C# variable initializations vs assignment

In a book I found following (translation): Initialization means assigning the value of the variable at the declaration time. int X=5 is called an initialization command. EDIT: It just says that term initialization is used only when you assign value at the declaration time. If you do it later, its just assignement (according to it -...

cin.get() not working

I wrote this simple program today, but I found that cin.get() refuses to work unless there are 2 of them. Any ideas? #include <iostream> using namespace std; int main(){ int base; while ((base < 2) || (base > 36)){ cout << "Base (2-36):" << endl; cin >> base; } string base_str = "0123456789abc...

Language syntax evolution and its semantics preservation.

Hello, I am investigating how a syntactic evolution of language affects its semantics. For instance, java's for loop syntax evolved in its version 5 to a compact one. Do the designers have to prove that even with this syntax the semantics are still preserved! May be this is a trivial example. So, in general, how can one prove that a lan...

Strange syntax behavior in C#

Hi All, I am just curious to know why this is allowed. int i=0;; I accidentaly typed that. But the program compiled. I noticed it after many days that I have typed ;; After that I tried with different symbols like ~, !, : etc etc Why is that not allowed where as first one is allowed. Just curious to know. ...

C# goto use - what else to use here?

Hi, I know using goto is something most people say to avoid, however I have read on various places that sometimes it is useful if you need simple code. Currently I have very simple program that needs to be repeated if user selects so: static void Main() { Restart: ... string UserChoice=Console.ReadLine(); if (UserChoice...

In c# what does 'where T : class' mean?

In C# what does where T : class mean? Ie. public IList<T> DoThis<T>() where T : class ...

Does anyone know how to write this SQL If statement better?

I have this IF statement in my Stored Procedure: if ((@someParam = 'C') OR (@someParam = 'I' AND @SomeOtherParam <> 2 AND @SomeOtherParam <> 4 AND @SomeOtherParam <> 5)) My question is can I check @SomeOtherParam in one shot, instead of having to check it 3 separate times? ...

Declaring instances in C#

Do I have to "double declare" every new instance in c#? Obj sb = new Obj(); VB is cheaper Dim sb as new Obj() and Python cheapest sb=Obj() ...

C# strudel sign

While coding in C#, I by mistake added a strudel sign before a variable in if statement (instead of exclamation mark). bool b = false; if (@b) { } I surprised it compiled successfully without any error. I wonder: What is the meaning of the above code? ...