read-only

What is the easiest, most concise way to make selected attributes in an instance be readonly?

In Python, I want to make selected instance attributes of a class be readonly to code outside of the class. I want there to be no way outside code can alter the attribute, except indirectly by invoking methods on the instance. I want the syntax to be concise. What is the best way? (I give my current best answer below...) ...

Checking if the file is already in use before opening (network drive, C#)

Does there exist any way in .Net to check before opening if a file (on a local network drive) is already in use? ...

Resticting access to method calls on read-only properties

I have a class that defines a read-only property that effectively exposes a private field, something like this: public class Container { private List<int> _myList; public List<int> MyList { get { return _myList;} } public Container() : base () { _myList = new List<int>(); } // some method tha...

How do I delete a directory with read-only files in C#?

I need to delete a directory that contains read-only files. Which approach is better: using DirectoryInfo.Delete(), or ManagementObject.InvokeMethod("Delete")? With DirectoryInfo.Delete, I have to manually turn off the read-only attribute for each file, but ManagementObject.InvokeMethod("Delete") doesn't appear to need to. Is there an...

Why can't I assign values to pointers?

After reading the faq's and everything else I can find, I'm still confused. If I have a char pointer that is initialised in this fashion: char *s = "Hello world!" The string is in read-only memory and I cannot change it like this: *s = 'W'; to make "Wello world!". This I understand, but I can't, for the life of me, understand how to...

Is Read-only property available in tree node in C#?

How to set tree node 'read only' in windows C#? Should not us disable, default. ...

Mark exported classes in Eclipse to not modify

Hi all, in my workpsace i do have SVN checkout classes and SVN export classes. I seperate the classes into two working sets. The exported classes are members of another feature based project and i am not allowed to change this classes inside my workspace. When i want to fix a bug or implement new features i want to be sure, that the ex...

const Dictionary in c#

I have a class in C# that contains a Dictionary, which I want to create and ensure nothing as added, edited or removed from this dictionary as long as the class which contains it exists. readonly doesn't really help, once I tested and saw that I can add items after. Just for instance, I created an example: public class DictContainer { ...

How do I open an already opened file with a .net StreamReader?

I have some .csv files which I'm using as part of a test bench. I can open them and read them without any problems unless I've already got the file open in Excel in which case I get an IOException: System.IO.IOException : The process cannot access the file 'TestData.csv' because it is being used by another process. This is a snippe...

Read-only array in .NET

Arrays are a fast way to iterate through an unordered set of items, and it's often nice for them to be read-only. While exposing arrays with the `readonly' keyword is useless because the contents of the array can still be altered, a ReadOnlyCollection<T> wrapper solves this. The problem is it's 4 times slower than a plain array in test...

PHP - Read-Only spreadsheet filetype?

I'm using a simple web-based PHP application that outputs a table as a spreadsheet header("Content-Disposition: attachment; filename=" . $filename . ".xls"); header("Content-Type: application/vnd.ms-excel"); //inserts tab delimited text But I'm finding the downloaded spreadsheet opens as a read-only file and must be saved locally and...

Make a foreign key field in a django form read-only, and still enable the form to be submitted

How do I make a foreign key field in a form read only but still allow this field to be recognized as valid once the form is submitted? According to W3C, disabled fields are left out once the form is submitted....using the code below, I can set the field as disabled, thus readonly, but my form doesn't go through def __init__(self, ...

.NET Framework: How to make RichTextBox true read-only?

Setting RichTextBox as “ReadOnly” doesn't prevent embedded objects (like equations) from being edited by double-clicking them. I could disable the control but then there is a gray background (can't be just changed with BackColor) and no way to scroll. I tried to override OnDoubleClick in a derived class but no success. ...

In SQL Server how to give only "read only" permission to all DB objects?

I need to give read only permission to a couple of users on the database so that they can get an understanding of the schema, logic in SPs, etc. But I do not want them to modify anything. I tried assigning the db_datareader role but it doesn't allow viewing SP name or code. What is the right role-combination to do this or do I need to wr...

C# CSLA business object dilemma: read-only vs read/write

I'm part of a team tasked to revamping our old VB6 UI/COBOL database application to modern times. Before I was hired, the decision was made (largely on sales, I'm sure) to redo the UI before the database. So, now we're using WPF and MVVM to great effect, it's been amazing so far, especially using CSLA as our Model layer. However, beca...

Creating read-only properties in Actionscript 3

Many library classes in AS3 have "read only" properties. Is it possible to create such properties in custom as3 classes? In other words, I want to create a property with a public read but a private set without having to create a complex getter/setter system for every property I want to expose. ...

Is there a way to modify foreach loop variable?

The following code gives an error message: #!/usr/bin/perl -w foreach my $var (0, 1, 2){ $var += 2; print "$var\n"; } Modification of a read-only value attempted at test.pl line 4. Is there any way to modify $var? (I'm just asking out of curiosity; I was actually quite surprised to see this error message.) ...

Is it possible to have fields that are assignable only once?

I need a field that can be assigned to from where ever I want, but it should be possible to assign it only once (so subsequent assignments should be ignored). How can I do this? ...

How to make a git repository read-only?

I have some git repositories accessed remotely through SSH and I want to make some of them read-only to prevent more pushes. Some people have remotes pointing to these repositories. These bare repositories were initialised --shared=group, so is setting file permissions to 660 for all files good enough to still allow SSH access, but disa...

how is read-only memory implemented in c?

I heard that in c, if I do: char *s = "hello world". The "hello world" is actually stored in read-only memory. I am not so clear about read-only memory. Can anybody explain? Is that like a flag to compiler that tells compiler that do not write into that section? ...