Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 6th, 2013, 11:10 AM
MynE MynE is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 35 MynE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 32 m 59 sec
Reputation Power: 1
Remove/Skip some words from JSON's data

Hi, I'm trying to find a solution to Skip or Remove some words from the data I got which is from JSON's files. I have a data like this:

aa = results[16]['message'], results[17]['message']

u'some headline text. http://aurlhere.com/somearticle/foryou \u2026', u'Another headline!\n\nhttp://www.somesite.com/somearticle.htm'

As you can see in my file, there's \u2026 which contains with backslash(\). The problem is when I tried to insert these data to mysql, it shows me an error because It can not come across the '\' line. Is there any idea to remove or skip this specific words? Please help me find out.

Last edited by ManiacDan : February 6th, 2013 at 12:05 PM. Reason: Removing overly political headlines.

Reply With Quote
  #2  
Old February 6th, 2013, 11:51 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,361 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 10 h 3 m 51 sec
Reputation Power: 383
Filter retains ASCII

possible python2 solution demonstration
Code:
>>> a=u'Denver ߪ'
>>> a
u'Denver \u07ea'
>>> print([ord(x)for x in a])
>>> print(''.join(c for c in a if ord(c) < 256))
Denver 
>>> 
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old February 6th, 2013, 12:26 PM
MynE MynE is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 35 MynE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 32 m 59 sec
Reputation Power: 1
Thank you so much for your reply it helps me lots. It works like you said but when I tried it with multiple data like

Code:
a = []

for i in range(10):
      a.append(results[i]['message'])

a = (''.join(c for c in a if ord(c) < 256))


It shows me an error :

a = (''.join(c for c in a if ord(c) < 256))
TypeError: ord() expected a character, but string of length 1245 found

Do you know the way to solve this solution at a time? because I want to fetch multiple data and convert it to a properly format before I insert into SQL. Anyway, I appreciate your answer so much, thank you

Reply With Quote
  #4  
Old February 6th, 2013, 01:33 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,361 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 10 h 3 m 51 sec
Reputation Power: 383
Since you're trying to write in python, learn about the various object containers. dict , list , set , frozenset , tuple , str , and all those I've overlooked like bytes , unicode .

Obviously, that is, obviously to a python programmer, you have a data structure that is more complicated than a unicode string whereas the implementation of the algorithmic idea I provided will not work with nested structures. Well, I won't count ['a','b'] as a nested structure.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Remove/Skip some words from JSON's data

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap