G_S 38 Junior Poster in Training

Oh my god! Are you sure you're not actually summoning Cthulu with that line of code, Jim? That's a really good example. And yes I agree that statement is nonsense. They are basically saying they know everything there is to come.

G_S 38 Junior Poster in Training

Hello people. I'm looking for FP examples that are very simple (very few lines, one-liners are even better) and that totally look like sorcery to a traditional imperative programmer. Can you help me with that? I want to show some old school programmers who are friends of mine but keep saying that all programming is exactly the same and that every single language in existence is a botchered, downgraded version of C. They also say that once you learn how to think the C way you'll be able to program in every other single language because they are mostly the same.

I am just starting out in FP, so I could only come up with a tail-recursive factorial and it's got them near brain-explosion mode because they think there is only one possible type of recursion.

Any other cool weid-looking examples?

G_S 38 Junior Poster in Training

Do you have several Python versions? Sounds like the module is not installed for the python.exe that gets called when you type "python". Double check your PATH variable.

Also, why don't you try calling django-admin directly? Do this:

Locate your Python installation folder (usually C:\python34), in there there must be a "Lib" folder (not libs). Inside that one you'll see a "site-packages" folder. That's where Django should be if it was installed correctly.

Now, inside "site-packages/django" you'll find a "bin" folder with django-admin.py. Try running it from the command line using something like: python <path_to_django>\django-admin.py

G_S 38 Junior Poster in Training

You normally install modules using pip install <package_name>. If everything goes well, you just need to import the module into your programs.

Have you tried this? What errors did you get?

G_S 38 Junior Poster in Training

This is old but maybe I can still help. First some questions: are you using a server? If so, which one? Also, which database will you use? Last time I checked there were problems with mySQL's driver for Python 3.5 (in case you need MySQL). Are you new to Python?

If you just want to run development server, Django comes with a built-in server suitable only for development.

If you still need help, please explain what is not working and I'll try to help. I had a lot of trouble with Django in the last couple months, so maybe I can help a litttle.

G_S 38 Junior Poster in Training

Well, I would first store the loaded content in a list, then populate the listbox with it.
Second, I would create a buton whose associated function performs a curselection() to get the selected items, then check if they exist in list 2 and if not, place them there. Finally this function would create a new file (you can either do it manually or use a csv library for that) and write the second list to it.

I did not understand, however, if you want to make the new file using the entire content of the second listbox or just the selected items.

G_S 38 Junior Poster in Training

Thanks for your response. Could do please be more specific? What do you mean by "require parse"? How do you add the content (could you please give me a snippet)??

G_S 38 Junior Poster in Training

Small correction: disregard the last curly brace. It doesn't belong there (and I don't know how to edit my post anymore...)

G_S 38 Junior Poster in Training

Hello everyone.

I am trying to make a simple to-do list program using PHP and the MVC pattern. I have managed to make the login page, the model and the controller for managing logins. It is working properly because it can discern if the user exists or not. After validating the user, it includes another page using require_once(). The problem is that it is displaying the contents of the new page (the one you see after loggin in) right below the login form instead of simply replacing the whole page with the new one. Here is the code. It is located in the index.php page:

<?php

include 'model/user_model.php';
include 'controller/user_controller.php';
include 'view/user_view.php';


$usermodel = new UserModel();
$usercontroller = new UserController($usermodel);
$userview = new UserView($usercontroller, $usermodel);

if(!isset($_SESSION)) {
  $userview->outputlogin();
}

if(isset($_REQUEST['name'],$_REQUEST['password'])) {


    if ($usercontroller->validateuser($_REQUEST['name'],$_REQUEST['password'])) {

        $userview->outputlogged();

    }else {
        $userview->outputlogin();
        echo "<p>Wrong user or password</p>";
    }

}


?>

the outputlogged() function does this:

 public function outputlogged() {

        require_once($this->usermodel->template['logged']);
        }
}

It simply outputs the logged.php page which currently only says "You logged in". The problem is that the message is appearing BELOW the login form instead of simply replacing the whole page with the one with the message. What am I doing wrong?

G_S 38 Junior Poster in Training

Thank you very much. I know it's widely discussed, but I had to resort to this website because my teachers really confused me when they told me that MVC is the same as third-tier architecture and that the data layer is the one in charge of the logic AND data...

But wait, you say the second layer holds the data model. Shouldn't that be the third layers job, data processing being the second's?

G_S 38 Junior Poster in Training

Alright. According to James' answer, the new design would be:

FIRST LAYER: GUI
SECOND LAYER: a class for storing and processing the data obtained from the GUI (lowercase, lematization, etc.).
THIRD LAYER: two classes: one for managing database connections and sql execution, and the other for building the SQL and asking the former class to run it.

Is this better then?

G_S 38 Junior Poster in Training

Hello everyone.

I am modeling a simple dictionary application using the presentation-business logic-data layer pattern. I already have the design but am not sure it is correct:

My presentatioon layer is a simple GUI where users insert their queries. They have a form for entering new words and their definitiom and also another form for querying the dictionary. I think this one is OK.

My Business layer is where the trouble starts: I have an Entry class which has the attributes id_number (for queries), word and definition. As for methods it has the standar CRUD operations. It aso has some transformation methods used for formatting the input (removing plurals, removing gramatica genders, etc.) The CRUD methods simply build a query using the attributes available and immediately instantiate a connection class.

The third layer would be the data access layer. The actual SQL pocessing is being carried out here. The previous object simply builds a query but it doesn't run it. This layer has a special class for running SQL after checking server connectiona nd all that stuff.

Is this properly implemented? Should the Entry class rather be in the data layer? If so, what should I punt in the logic layer?

Thanks in advance.

G_S 38 Junior Poster in Training

Yes, that's true. I think that later on I'll have to use some sort of ORM to solve that problem.

G_S 38 Junior Poster in Training

I used this program http://alexdp.free.fr/violetumleditor/page.php

It's perfect for learning basic UML modelling.

So, you don't see any problem with the structure?

G_S 38 Junior Poster in Training

Here is my class diagram. Took me a while to upload it due to technical issues with my computer, but here it is. The classess at the bottom are non-abstract. The other ones (5) are abstract. The run_query and connect methods are all different for each of the bottom classes. The disconnect() method is exactly the same, so I implemented it in the BaseConnection class.

One thing to note is that the concrete classes have no new attributes, it's the implemented methods that make them different from their parents and siblings.

ClassDiagram.jpg

G_S 38 Junior Poster in Training

Thank you very much. I have made several pseudoasbtract classses with NotImplementedError and NotImplemented. I notice that I went from very gneral classes to very specific classes, so I think it's correct. I'll write the final classes later and let you know of the final result (I hope i don't come across any errors in the nonabstract classes.)

G_S 38 Junior Poster in Training

Hmm, I'm currently creating the intermediate pseudoabstract classes. I really need the attributes, so question: should the NotImplementedError be raised by the constructor too? Or should I have the constructor create the attributes I want so that child classes can inherit them?

G_S 38 Junior Poster in Training

Hmm, I think I got it. If inheritance is a specialization, then my most general class should be the parent. So it goes like this:

Base (common attributes and methods) -> MySQL | Sqlite.

Now there is one issue left: I have a postgres connection which looks exaclty like a mysql connection:

The MySQL connection:

class MySQLConnection:

    def __init__(self, a_server, a_database, the_user, the_password):


        self.server_ip = a_server
        self.database = a_database
        self.user = the_user
        self.password = the_password

        self.connection = None
        self.cursor = None
        self.error = None

The postgres class:

class PostgresConnection:

    def __init__(a_server, a_database, the_user, the_password):

        self.server_ip = a_server
        self.database = a_database
        self.user = the_user
        self.password = the_password

        self.connection = None
        self.cursor = None
        self. error = None

They are twins! Except for the fact that their connect, disconnect and run_query methods use very similar but not equal code to perform those actions. A PostgreSQL connection IS NOT a MySQL connection, although they look really similar in that they have the same basic attributes BESIDES the base attributes of any connection.

What should I do then? Another base class that adds the host, database, user and password attributes and that is the aprent of postgres and mysql? Or simply leave them as twins?

G_S 38 Junior Poster in Training

I see. I think I'll go with the simple superclass-subclass model. BUt there is then one question left: if the superclass has attributes A,B,C and D, but I only need A and B, what should the child class do to not inherit C, and D?

Look at this code:

class MySQLConnection:

    def __init__(self, a_server, a_database, the_user, the_password):

        self.server_ip = a_server
        self.database = a_database
        self.user = the_user
        self.password = the_password

        self.connection = None
        self.cursor = None
        self.error = None

And the this one:

class SQLite3Connection:

    def __init__(self, db_path):

        self.path_to_database = db_path

        self.connection = None
        self.cursor = None
        self.error = None

The second class needs only three of the attributes of the first one, and adds a new one (the connect method initializes the = None attributes later). When I inherit, will the child class inherit the useless attributes too? Should I write a new constructor for the child class? If I do so will it forget the inherited attributes?

G_S 38 Junior Poster in Training

Hello everyone. I am currently making some database connection modules in Python inb order to learn Python's approach to OOP and also to lear how to connect to databases via Python. I successfully made a package with modules for postgres, mysql, sqlite3, and MongoDB. The classes simply connect, disconnect and run queries of any type. Everything is working fine now.

However I noticed that the code is nearly the same. For example, the connect and disconnect methods are exactly the same. Also, postgress and mysql connections have exactly the same number of attributes. Inheritance came to mind, but some classes have less attributes. For example, my sqlite3 class has less attributes because this connection doesn't care about server, port, username or password.

So, what should I do? I can use inheritance but how do I remove the unwanted attributes? Should I make an abstract class stating the methods (they are nearly the same for all subclasses) but no attributes?

G_S 38 Junior Poster in Training

I do, actually. I started with Python 3; it was my first language and my first contact with computer science and programming in general. The thing is that, in my current job, they use an NLP tolkit that relies on Python 2.x so...

So, by impoting all that I'll be able to get my Python 3 programs to run in Python 2.7+?

And thank you for your great reply!!

G_S 38 Junior Poster in Training

Don't I just need the unicode_literals module?

G_S 38 Junior Poster in Training

I have this:

dic = {'ál':1, 'él':2}
string = "ÉL"
number=dic[string.lower()]

and it's giving me a KeyError.

I realize then that 'ÉL'.lower() is giving me 'Él', i.e. it is not affecting the É at all because some weird Python 2.x encoding issue. Can somebody help me please? I can't tell users to write always in lowercase.

G_S 38 Junior Poster in Training

Ah Alright. So far it seems to be compatible with all I have done. Now for the second subquestion: if I want to use a full database, not the express version of Microsoft's, what would be a suitable candidate given the nature of my project? I basically want the possibility of using a nice GUI like Microsoft's. Should I really go with MySQL? What about Postgres? Are they too big for my project?

G_S 38 Junior Poster in Training

I See, Jim, what is the name of that free SQL management console?

G_S 38 Junior Poster in Training

Tha's good to hear, but they told me the express version lacks some features we will need. Don't know if it's true, though.

G_S 38 Junior Poster in Training

Hello. I am currently studying database design at my local university. They use Microsoft products there (Microsoft SQL Server 2008/2012), but we can't use them at home because of the licensing. I have two questions:

1 - Is there anything in the world of Open Source that I can use to process those Microsoft Files? I mean: can't I use Microsoft Management Studio to save the database using another format and then open that database at home with another program that does the same as Management Studio (you know, that cool visual editing of tables and relationships).

2 - The final project involves designing and implemening a database for a fictional company of one's choice. Turns out I could probably make the database to solve a particular problem at work, so it would be more or less real. If so, what database management system do you suggest? Here are the characteristics: We have no Microsoft SQL Server (actually no database server at all) and want to go for a FREE DBMS. The business is translation: it's a database for storing clients, translators (with their availability), proofreaders, processed and unprocessed texts, etc. I have been advised against MySQL because it was bought by some company which could probably bury it; I was also told it has too many security holes. I saw Maria DB but know nothing about it. I have also seen postgres, firebird, sqlite.

Thanks in advance.

G_S 38 Junior Poster in Training

Great. Thanks again everybody. I finally understood this normalized/denormalized table stuff. In fact, I even learned more about tables from these answers than from my teachers'.

Thanks!

G_S 38 Junior Poster in Training

Thank you for your input. I was told that denormalized databases are a mistake, that they are monster to avoid and something professionals never do...

So I should have a persons table and the proofreader and translator are not people but simply jobs they can take? Did I get it right?

G_S 38 Junior Poster in Training

Hello everybody. I have a question related to database design:

I am trying to make a database for my translation mini-company. I have two entities: translators and proofreaders. The problem is that some of our translators double as proofreaders, that is, they can work in both areas. The question is, is it OK to have the same person appear in different tables? I know that having the same person appear in the same table more than once is troublesome.

Thanks in advance.

G_S 38 Junior Poster in Training

What do you mean? I can simply throw them in the src folder and that's it? I thought everything had to be inside a package, good to know that.

G_S 38 Junior Poster in Training

Hy, I have a beginner question: when using PyDev should all my programs be inside a package or not?

G_S 38 Junior Poster in Training

OK I'll reply myself since I solved it on my own (I'm such a genius):

The problem was that some networking wizard I had recently used changed the name of the machine back to localhost, and pydev was still trying to connect to the Python shell using the old name. I restored the old name and voilà!

I'm amazing, I know.

G_S 38 Junior Poster in Training

Hello everybody. Lately, I'm having a problem with PyDev which is driving me crazy:

It is failing to connect to the Python console, therefore, many built-ins appear as errors (None, name, the os modules, etc.). I have tried downgrading PyDev, I have tried disabling IPv6, I have tried disabling my Linux firewall, I have tried re-installing everything and no luck...

This is rendering the entire IDE unusable because it keeps listing errors which are not: a simple x = None gives a "undefined variable None".

Another thing is that this error is not consistent, sometimes it connects to the python console, sometimes it doesn't.

I'm running Eclipse Juno on Mageia 2

I would appreciate any help, this is driving me crazy.

G_S 38 Junior Poster in Training

Hahaha, look at my other thread "can objects be attributes", where I asked (or tried to) if an object can contain other objects inside itself in the form of an attribute. What I was asking was actually if composition (I didn't know the concept at that time) was possible in Java. My teacher said it was not possible... That's why I just got the passing grade and forgot about it.

G_S 38 Junior Poster in Training

Thanks again everybody. Like I said in another post. I just got a passing grade and forgot about the course. This teacher sucks so I continued to study by myself. The last java-related thing he said is that Java is a purely compiled language and that interpreted/scripting languages are inferior and should be taught or used. I really wonder what kind of engineers will this University produce with such teachers in it...

G_S 38 Junior Poster in Training

Thank you everybody for your responses and sorry for the late reply. Turns out my teacher is really bad, so I simply passed the fisr three tests to ensure a passing grade for the course and stopped going to class regularly. The last time I checked they were accessing the second and third elements of a stack without first poping the ones above them...

G_S 38 Junior Poster in Training

Thaks for your help. So:

1 - This is used for referring to this class' variable whose name is similar to the method's parameter?
2 - Children inherit their parent's methods and attributes BUT using the paren't setter doesn't set the children's variables? If so, then using the childrens setter will only set the age and, id and name of ONE child and not the parent's or the other child's?
3 - Does this mean that in our example, my teacher wasn't truly using inheritance because he actually used the parent for the calculations (he rather extracted the parent's age, id, and name and used them as though they were the childrens')?

G_S 38 Junior Poster in Training

I'm having a similar problem. I think I read somewhere that constructors are not inherited. But I think you can call the parent's constructor using super (I think).

xHellghostx commented: Yes you are right.. I used the super and it worked just fine.. Thank you. +0
G_S 38 Junior Poster in Training

Hello people. I need an explanation about inheritance I got a little confused in class:

This is the modelling problem:

There are two objects: doctors and patients. They are expected to have only the following attributes:

Doctors have: name, age, id, and salary
Patients have: name, age, id, and disease type

Since three of the 4 attributes are repeated, we were told to use inheritance. So we created a People class containing name, age and id as attributes and one method for setting those variables to a given value.

Here comes the problem:

In class we instantiated the parent class together with the other 2 children. Then, the teacher used the set method OF THE PARENT CLASS to take care of the 3 common variables and then used the children's methods to set the remaining variables that were still not set. Finally, he accessed the age, id and name variables of the parent class, and the salary and disease type variables of the children classes

Is this truly inheritance? Can't we use only the children, since they will also have the setter method created in the parent along with the parents three attributes?

Let me know if you don't undertand my question. I admit it's a little confusing

G_S 38 Junior Poster in Training

LOL. Yup. I asked him directly and he was talking about THE main method. He didn't like it when I showed him a Java program with a non-existing return type and an compiler complaining about it.

G_S 38 Junior Poster in Training

@ JamesCherrill: He IS grading my homework. I'm gonna have to choose between pass the course and learn properly... He had us make a calculator (similar to the project for beginners on this site) but he has a weird conception of objects and classess... and fields (attributes for him)...

@mvmalderen: Yes, he was explicitly talking about Java.

Thank you all guys again. It is clear now regardless of what my teacher says.

G_S 38 Junior Poster in Training

@JamesCherrill: My teacher means "variables can't be references to objects from other classes". Which,as you and everybody else says, is not really true.

@~s.o.s~: Thank you very much for your anwer too. It's extremely clear, especially the part about mistakenly thinking that objects have copies of the field data.

Thank you everyone else. All the explanations were very clarifying. I decided to rather study by myself, since the same teacher today said that a main method doesn't require a void return type, or any return type at all. The Java compiler disagrees...

G_S 38 Junior Poster in Training

Hello I am a little confused. I had always thought that a class can have objects from other clases as attributes. My teacher recently told me that this is not true... so I am confused now: if one of the attributes of my class is a String, would that be an object inside my class???? Teacher says it's simply a variable...

G_S 38 Junior Poster in Training

I'm pretty sure it's a school assignment. I got the same assignment a while ago. It looks daunting at first for newcomers, but it is quite easy. Try to solve the problem in your head or using a piece of paper without actually coding, just think about a solution and ask questions if you encounter some problems.

G_S 38 Junior Poster in Training

There is another one for OpenOffice (I think): http://wiki.openoffice.org/wiki/PyUNO_bridge

I have always ben curious about this. Can't you just download a module and use it in you program instead of forcing users to install the whole thing?

G_S 38 Junior Poster in Training

I wish Zecharia Sitchin's books were true and this machine would find something nice there

G_S 38 Junior Poster in Training

Small update: I found out about those two lines on my own. Here is the code:

new_html = html.replace('<', '\*<').replace('>', '>\*')

html_as_list = new_html.split('\*')

replacements = {'<b>':'<strong>', '</b>':'</strong>', '<table>':'<p>','</table>':'</p>','<td>':'<p>', '</td>':'</p>', '<tr>':'<p>', '</tr>':'</p>'}

for i in range(len(html_as_list)):
    if html_as_list[i] in replacements:
        html_as_list[i] = replacements[html_as_list[i]]


new_html = "".join(html_as_list)

return new_html

It's now working pretty well now, but... is it more efficient than my first version of the code?

The first version was

def tag_remove(HTML_string):
    clean_HTML = a_string.replace('<b>', '').replace('<i>', '').replace('<p>', '').replace('<h1>', '') #etc.
    return cleaned

But there were 120+ .replace(something, something) statements. Is this new code really more efficient?

G_S 38 Junior Poster in Training

Thanks for your suggestions. I'll try using beautiful soup in future projects, since I think it is excellent but don't like installing full libraries to use just one function.

I then decided to take inspiration from wooooeee's approach:

So far I managed to turn the string into a list including both words and tags:

test_html="""<html>
<head>
<title>Should not be removed</title>
</head>
<b>bold test</b>
</html>
"""
new_html = html.replace('<', '\*<').replace('>', '>\*')
html_as_list = new_html.split('\*')

This produces a list where tags AND words are separate elements. It also produces crap (empty strings), but join deals with that later.

Next, I have a dictionary of changes:

replacements = {'<b>:'<strong>'}

That is what I've got so far. Now the plan is:

for entry in html_as_list:
    #if entry is a key in replacements:
        #replace it with the corresponding value#
    else:
        pass
return "".join(new_html)

Can somebody help me with those two commented lines? Is there a python function for doing that?

G_S 38 Junior Poster in Training

Hello.

I am working on a personal project. It's basically a program for changing specific tags from certain HTML files.

So far, everything works. The GUI and the logic a work but I know the main function is wrong because it looks like this:

def tag_remove(HTML_string):
    clean_HTML = a_string.replace('<b>', '').replace('<i>', '').replace('<p>', '').replace('<h1>', '') #etc.
    return cleaned

Is there a way of doing this using a data structure like a list, tuple or dictionary? I don't want it to be so recursive. I was thinking of a dictionary where the key would be the tag to replace and the value the value for which it should be replaced. But I don't know how to do that.