Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

The following code will clear the folder recursively:
***
private void clearFolder(string FolderName)
{
DirectoryInfo dir = new DirectoryInfo(FolderName);

foreach(FileInfo fi in dir.GetFiles())
{
fi.Delete();
}

foreach (DirectoryInfo di in dir.GetDirectories())
{
clearFolder(di.FullName);
di.Delete();
}
}
***
4 years ago
***
decimalVar.ToString ("#.##"); // returns "" when decimalVar == 0
***
or
***
decimalVar.ToString ("0.##"); // returns "0" when decimalVar == 0
***
4 years ago
The following also worked for me. ISO 8859-1 is going to save a lot, hahaha - mainly if using Speech Recognition APIs.

Example:
***
file = open('../Resources/' + filename, 'r', encoding="ISO-8859-1");
***
4 years ago
In Python 3.x, raw_input was renamed to input and the Python 2.x input was removed.

This means that, just like raw_input, input in Python 3.x always returns a string object.

To fix the problem, you need to explicitly make those inputs into integers by putting them in int:
***
x = int(input("Enter a number: "))
y = int(input("Enter a number: "))
***
4 years ago
Dereferencing a pointer means getting the value that is stored in the memory location pointed by the pointer. The operator * is used to do this, and is called the dereferencing operator.
***
int a = 10;
int* ptr = &a;

printf("%d", *ptr); // With *ptr I'm dereferencing the pointer.
// Which means, I am asking the value pointed at by the pointer.
// ptr is pointing to the location in memory of the variable a.
// In a's location, we have 10. So, dereferencing gives this value.

// Since we have indirect control over a's location, we can modify its content using the pointer. This is an indirect way to access a.

*ptr = 20; // Now a's content is no longer 10, and has been modified to 20.
***
4 years ago
***
FILE *file;
if((file = fopen("sample.txt","r"))!=NULL)
{
// file exists
fclose(file);
}
else
{
//File not found, no memory leak since 'file' == NULL
//fclose(file) would cause an error
}
***
4 years ago
Print the least significant bit and shift it out on the right. Doing this until the integer becomes zero prints the binary representation without leading zeros but in reversed order. Using recursion, the order can be corrected quite easily.
***
#include

void print_binary(unsigned int number)
{
if (number >> 1) {
print_binary(number >> 1);
}
putc((number & 1) ? '1' : '0', stdout);
}
***
To me, this is one of the cleanest solutions to the problem. If you like 0b prefix and a trailing new line character, I suggest wrapping the function.
4 years ago
In Python 3.6, f-string is much cleaner.

In earlier version:
***
print("Total score for %s is %s. " % (name, score))
***
In Python 3.6:
***
print(f'Total score for {name} is {score}.')
***
will do.

It is more efficient and elegant.
4 years ago
The problem is with the string
***
"C:\Users\Eric\Desktop\beeline.txt"
***
Here, \U in "C:\Users... starts an eight-character Unicode escape, such as \U00014321. In your code, the escape is followed by the character 's', which is invalid.

You either need to duplicate all backslashes:
***
"C:\\Users\\Eric\\Desktop\\beeline.txt"
***
Or prefix the string with r (to produce a raw string):
***
r"C:\Users\Eric\Desktop\beeline.txt"
***
4 years ago
You need to instantiate a class instance here.

Use
***
p = Pump()
p.getPumps()
***
Small example -
***
>>> class TestClass:
def __init__(self):
print("in init")
def testFunc(self):
print("in Test Func")


>>> testInstance = TestClass()
in init
>>> testInstance.testFunc()
in Test Func
***
4 years ago
*~version* “Approximately equivalent to version”, will update you to all future patch versions, without incrementing the minor version. ~1.2.3 will use releases from 1.2.3 to <1.3.0.

*^version* “Compatible with version”, will update you to all future minor/patch versions, without incrementing the major version. ^2.3.4 will use releases from 2.3.4 to <3.0.0.
4 years ago
To normalize the arguments like a regular javascript function would receive, I do this in my node.js shell scripts:
***
var args = process.argv.slice(2);
***
Note that the first arg is usually the path to nodejs, and the second arg is the location of the script you're executing.
4 years ago