Programming

error in python code

Learn Programming - Thu, 11/15/2018 - 09:32
def nextDay(year,month,day): if day<30: return year,month,day+1 else : if day==30: if month<12: return year , month+1,1 else: return year+1,1,1 def valid_date(y1,m1,d1,y2,m2,d2): while y2>=y1: if y1==y2: if m1>m2: return False break else : if m1==m2: if d1>=d2: return False break return True #print valid_date(2012,5,2,2012,10,1) #print valid_date(2010,5,2,2015,2,3) def daysBetweenDates(year1,month1,day1,year2,month2,day2): count=0 p=[year1,month1,day1] q=[] #q=[year2,month2,day2] #self.assert_(boolean expression, 'message') while valid_date(p[0],p[1],p[2],year2,month2,day2): p=nextDay(p[0],p[1],p[2]) print p count+=1 print count print valid_date(p[0],p[1],p[2],year2,month2,day2) return count print daysBetweenDates(2012,12,27,2013,1,1)

I got this error in run

(2012, 12, 28) 1 True Traceback (most recent call last): File "C:\Users\M&A\Desktop\try.py", line 46, in <module> print daysBetweenDates(2012,12,27,2013,1,1) File "C:\Users\M&A\Desktop\try.py", line 42, in daysBetweenDates print valid_date(p[0],p[1],p[2],year2,month2,day2) TypeError: 'NoneType' object has no attribute '__getitem__' (2012, 12, 29) 2 True (2012, 12, 30) 3 True None 4 [Finished in 0.126s] try.py22:31 CRLFUTF-8Python Not on branch71 files

submitted by /u/Eng_AfafM
[link] [comments]

Drupal Dev Thursdays: Post here with development questions or discussion

Drupal - Open Source Content Platform - Thu, 11/15/2018 - 09:06

This is the weekly thread for development questions or chit-chat that doesn't belong in the Monday Beginner Questions thread. All questions/comments/ranting about Drupal dev is fair game.

(Check out the weekly post schedule in the sidebar)

submitted by /u/AutoModerator
[link] [comments]

[C#] Loading .csv file into a Dictionary<DateTime, int[]> possible ?

Learn Programming - Thu, 11/15/2018 - 08:51

Hey guys,

I am fairly new to programming in general and i'm currently stuck on a issue that I cant solve to save my life.

My program basically saves the user input (6 different buttons) into an int array + the DateTime (before the int array) The data in the .csv file looks like this:

[14.11.2018 16:26:18 1,1,2,0,0]

[15.11.2018 09:05:49 4;1;1;2;0]

(DateTime; Variable 1, Variable 2, Variable 3, Variable 4, Variable 5)

The part of the code that writes the data into the .csv file looks like this and works perfectly fine:

private void btnSaveUserData_click(object sender, RoutedEventArgs e) { int[] iNewDataArray = new int[] { iVariable1, iVariable1, iVariable1, iVariable1, iVariable1 }; Dictionary<DateTime, int[]> oDateTimeAndIntDictionary = new Dictionary<DateTime, int[]>(); oDateTimeAndIntDictionary.Add(CurrentDayTime, iNewDataArray); using (System.IO.FileStream fileStream = new System.IO.FileStream(@"C: \Users\--------\Desktop\--------\--------\SaveFile.csv", System.IO.FileMode.Append, System.IO.FileAccess.Write)) using (System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(fileStream)) { foreach (KeyValuePair<DateTime, int[]> kvp in oDateTimeAndIntDictionary) { streamWriter.WriteLine("{0} {1}", kvp.Key, string.Join(";" , kvp.Value)); } } }

Now to the actual problem:

I want to know if its possible to read the .csv file and save the data in exactly the same way that I wrote it in. I tried hundreds of different solutions this is just the latest one that also doesn't work.

private void Button_Click(object sender, RoutedEventArgs e) { using (System.IO.StreamReader streamReader = new System.IO.StreamReader(@"C: \Users\--------\Desktop\--------\--------\SaveFile.csv")) { var oTempDictionairy = new Dictionary<DateTime, int[]>(); while (!streamReader.EndOfStream) { var line = streamReader.ReadLine(); var values = line.Split(','); oTempDictionairy.Add(values[0], int.Parse(values[1])); } }

The 2 Errors I get are:

  • CS1503 C# Argument 1: cannot convert from 'string' to 'System.DateTime'
  • CS1503 C# Argument 2: cannot convert from 'int' to 'int[]'

Does my approach even work ? And if it doesn't, what would be the best way to go about loading the data from the .csv file to use it on program start ?

submitted by /u/Demokrit_44
[link] [comments]

Trying to seed web scraped dataset into my database. Image fields are not exactly in image format. What am I missing?

Learn Programming - Thu, 11/15/2018 - 08:23

Hi everyone,

I've found a dataset that webscraped many recipe sites. For my graduation project I'm trying to seed that dataset into my models in the database. The dataset is a .json file and has "recipe name", "ingredients", "directions", "recipe image" information. The recipe image field on each recipe does not end with .jpg, .png or anything like that to indicate this text I see is an image. They don't refer to a link either and there are thousands of recipes like this. It doesn't look like it's a mistake but I couldn't figure out why they are not in the regular image format, and is there a way to get the image out of them? If it'll make any difference, I'm using Sequelize and Javascript (irrelevant but also Express, React and Redux) for the project.

submitted by /u/dilandy
[link] [comments]

Some Javascript questions I have after hacking my way through projects without knowing everything...

Learn Programming - Thu, 11/15/2018 - 07:35

I have some questions from my learning now of different JS topics and concepts. Mainly about Firebase, React and more.

  1. I am using Firebase Cloud storage for a database and authentication. Is it secure if I take input values from the login form and use a function calling on Firebase to log them in. Then I show them React components based on a Boolean variable of if they are logged in or not. Is that secure? This all happens in javascript front end I guess, I’m just wondering if it is a problem for security of data?
  2. Secondly I have another function that checks if they have “admin” access (a property in the user database) it then renders the admin only dashboard. Is this secure as well or will someone be able to edit the variable and render things they shouldn’t have access too?
  3. With Firebase and react it seems like there isn’t any “backend” things I need to code to make an application? Am I looking at this wrong? Is Firebase a backend? What would Node.js add?
submitted by /u/PullupNparkthebenz
[link] [comments]

Newbie CSS styling Question

Learn Programming - Thu, 11/15/2018 - 07:30

Hey Guys -

Brand new to coding and just started learning HTML and CSS a few weeks ago. Decided I'd try to work on replicating the facebook login page as a first project. I'm running into a few issues with styling a button on the page. Could somebody help explain why my sign up button is looking so drastically different from the one on the facebook login page? Also, ignore the basic coloring in the codepen, I'll update that later, just want to make sure I have the concepts down.

https://codepen.io/cfalvo01/pen/oQWMJm

Thanks!

submitted by /u/nyg1220
[link] [comments]

Receiving byte data type in Processing(java)

Learn Programming - Thu, 11/15/2018 - 07:15

I'm trying to send an image over a byte array data stream in processing with the code below, but as networking is poorly documented in processing, I think there's only a way to receive a string and convert it to a byte array, which processing sees as invalid

PImage fback=Recieve(loadBytes(c.readString()), 640, 480, 3);

the paramaters of the recieve function are as follows:

PImage Recieve(byte[] data, int w, int h, int ch)

(ch is the color channel, typically 3) Here is my send function:

s.write(broadcast(video));

Full code for host client: https://pastebin.com/L6Y6FTKp P.S. If you think I'm missing anything, just ask for it.

submitted by /u/WENISBENIS100000
[link] [comments]

Any ideas on how to quickly classify images using Python?

Learn Programming - Thu, 11/15/2018 - 07:14

I have a small project in mind but need some ideas on how to implement it. Let me explain what I would like the Python script to do.The script should take a screenshot of part of my computer screen (from a windowed program). Then it would check a folder to see if it has captured the same image previously. If yes, it would retrieve the filename of the image in question. If not, the image is stored to the database.

This sounds simple but: What if I one day capture images A, B, and C, and store them in a folder as these are new images. The next day the window of the program where I capture the images is slightly shifted, so now when I capture the same area of my screen, images A, B, and C will all be classified as new images because the pixels do not correspond to the pixels of the images in my folder.

Another problem might be speed. Wouldn't it be slow to compare every pixel of a captured image with every pixel of the image in my folder and loop through them to find a match?

Does anyone have any ideas how to accomplish this quickly with some error tolerance (program window not exactly the same size or at the same coordinates every time)?

Edit:

I found this solution for taking screenshots of a window and moving the window to a specified location. This solves one problem, but I still don't have anything on how to check if the captured image is already in a folder.

submitted by /u/Peanuts_or_Bananas
[link] [comments]

Salary Negotiation Done Right

Programming - Thu, 11/15/2018 - 06:47
Categories: Programming

Pages